3 ms·
Take a look at Google's AMP script: https://www.google.com/xjs/_/js/k=xjs.av.en.1ic8JaUStX4.O/m=jsa,r,d,hsm,ampsa,amp,tnqaT/am=AACAAORCDwDgqwFWAg/d=1/br=1/rs=A
by londons_explore 7y ago
Take a look at Google's AMP script:
https://www.google.com/xjs/_/js/k=xjs.av.en.1ic8JaUStX4.O/m=jsa,r,d,hsm,ampsa,amp,tnqaT/am=AACAAORCDwDgqwFWAg/d=1/br=1/rs=ACT90oFDGnudWjXLeDH-NewC5hLtO_NGLw https://www.google.com/xjs/_/js/k=xjs.av.en.1ic8JaUStX4.O/m=...
Ask yourself... Is that really the minimum amount of script needed to render a basic fast text and images only webpage? Notice the handcoded crypto functions? Notice the copious numbers of debugging functions and log messages and error messages? Notice the large numbers of copyright notices and complete license texts.
This stuff, if Google's dream comes to fruition, will be downloaded billions of times per day. For every byte of cruft in this file, an ethernet cable needs to be installed/upgraded somewhere.
We shouldn't let Google get away with such massive inefficiency in the name of efficiency.
- IanCal 7y agoSurely it should be downloaded rarely and cached heavily?
- technion 7y agoCheck the advertised site, https://amp.dev/ https://amp.dev/, and look at the headers for v0.js. I'm seeing an "expires" tag of "now", a cache-control header of 'private' and 'max-age' of 50 minutes. You'll also see the 105KB Javascript used to support animated gifs, 46KB amp-bind which allows documents to "add interactivity", and several others.
- snek 7y agoThe sad truth is that Google's goal isn't efficiency, it is keeping people on Google's property. The best way to do this is to make people package their websites into little bundles that are safe for Google to preload. They're even working on a way to capture sites that don't want to invest in AMP (signed exchanges).
- skybrian 7y agoAn aside: one interesting thing about this is that Google's lawyers believe that copyright notices are required in minified JavaScript, and other people don't. Who's right? Is everyone else breaking copyright agreements?
- snek 7y agoMany licenses require that the license be distributed with the code. uglifyjs, babel minifier, and google closure compiler all try to preserve license information.
- sidcool 7y agoHow does one even begin to understand this script. I feel dumb.
- technion 7y agoYou're not meant to. It's minified and rewritten by the Javascript compilers. I believe this would be the place to find anything you want to read: https://github.com/ampproject/amphtml https://github.com/ampproject/amphtml
- jspash 7y agoI count 185 "try" statements with only 162 "catch". I don't know much about javascript, but could someone explain what happens with the 20 that don't get caught? Do they bubble up and get caught by another "catch"? Or is this indicative of lots of "holes" in the code path?
- vsviridov 7y agoYou can have try/finally without the catch.
- jspash 7y agoOk, fair enough. But then does that lead to a "fatal error" of some sort? I'm curious because I find AMP page quite buggy. ie. not loading at all. Or loading, then reloading a blank page. And thought maybe these were the "dead end" code paths.
- dmitriid 7y agoIt’s caught by a higher-level catch if there is one. Try blocks without a catch are a sign of any of these: poor coding, remnants from refactoring, features started and abandoned, possibly result of some build steps combining and optimising code.
- vimslayer 7y agoTry without a catch is fairly common and IMO quite fine when it's not the current method's job to deal with an error but it is its job to clean up state or some resources. async showImage() { this.showLoadingSpinner = true try { this.imageData = await fetchImageData() } finally { this.showLoadingSpinner = false } } There might be a parent class/component/whatever that deals with errors and shows them to the user. The image component is responsible for showing the loading spinner and it shouldn't be left spinning if there's an error.