I am a little surprised to find such an issue in Google software as it is a topic for first semester CS undergraduates ;-)
Since it's accessibility based, it's more laudable than teaching CS students how to center a div, but it's not like it really requires a mentor of some sort to express the nuances of, right? Or even if it does, it's still design.
A good CS degree definitely has the space to teach some basics in that area. To mention Gestaltgesetze, to explain human perception a bit, and give an introduction into usability. You do not get a useful developer in the end otherwise
Not all developers do stuff with UI, and of those that do not all do anything with a UI that is actually graphical beyond a terminal.
> since you need to understand basics of human perception to understand compression in that area (jpg, mp3), they talked about stuff like that.
That is a good reason to teach it, and counters my overly assertive original comment.
> Full-page screenshots. Take a screenshot of the entire page, from the top of the viewport to the bottom.
I'm surprised to see the Chrome developers not know what 'viewport' means.
Hardware (laptops, phones), and browsers js and rendering engines, are all 10x faster than they were 10 years ago, giving 100x to 1000x overall speedup. Think about that, it is truly incredible. But web pages are also 100x larger and less efficient than 10 years ago. This is absolutely not justified by productivity increases. This is just how the world / humans seem to work.
Remember when Emacs meant Eight Megabytes And Constantly Swapping?
... and daily standups? so busy working that there is no time to do the job
From my limited knowledge of your situation this seems like the last move to take. I would try the following, in roughly this order:
Serve libraries (Angular, jQuery) from a CDN to at least have the chance of hitting a browser cache on a visitor's first encounter with your site.
Use a minifier to strip all the unnecessary comments and whitespace (in addition to other benefits from minimization).
use gzip to compress the remaining minified files.
Those alone will likely significantly impact your load times. At this point, the remaining dead code should be relatively small and you can look into tools for surgically removing it.
This part is more of a shameless plug, but I believe public/industry/developers should be aware of what tools & techniques academia develops so that the researcher's efforts can be more useful. There are some static analyzers for JavaScript such as JSAI, SAFE, and TAJS (disclaimer: I'm working on a project related to JSAI on the lab which developed it). These static analyzers can discover the dead code if given all the entry points however:
- They don't have facilities to report the dead-code AFAIK (this is a trivial thing to add _in theory_, if there are parts of the program _unvisited_ by any of these, that part of the program is guaranteed to be dead). If somebody wants to add such a facility to any of the tools they are welcome. In case of JSAI, I'm willing to provide them all the information I can.
- They are conservative (e.g. sound) tools and may find too few dead code results.
- They don't play well with `eval` & friends in general although they try their best[0], the web frameworks rely on eval-like highly-dynamic approaches a lot to be generic enough and that hurts precision of such analyses dramatically.
[0]: https://pdfs.semanticscholar.org/8140/feec021818815c55a43b54...
[1]: https://www.cs.purdue.edu/sss/projects/dynjs/eval-TR.pdf
We're starting to get there.
JS Modules gives us static exports/imports, so we can statically analytics the dependency graph and identify functions that aren't used and do tree-shaking to remove them. Rollup and Webpack2 already does this, but there's more to go.
CSS Modules creates a contract between the your CSS and what uses it. As you have to import it, and exports are static, you can understand which style files are imported where. Next step would be to understand which classes are used inside that module and strip those that remain unused. This is theoretically possible (providing you use a more 'statically safe' syntax), but tooling hasn't yet popped up to do this.
[1] http://blog.mgechev.com/2016/06/26/tree-shaking-angular2-pro...
Ah, so this is how front-end got the way it is.
Plus for the time you spend chasing compat issues, writting wrappers, choosing small libs and packing it all together, you could have done your site. For less than 40ko.
People are not blinking at including react ecosysteme, which is huge. But attack jQuery ? Seriously ?
I don't know about you, but usually my projects last longer than a week, so those sorts of savings don't represent a significant chunk of my overall development time. Also, I'm not a shit programmer, so I can actually write a for loop that does what I want on the first try. I've spent more time trying to figure out jQuery's goofy syntax and what the hell it's doing with AJAX queries than it has ever saved me in development.
Event the damn native APP for hackernews, using only JSON, is not usable in 2G.
Why doesn't fetch and its polyfill cut it?
And even then. You need to encode params manually.
And of course no middleware, so for special decoding or repeating headers, you end up writting a wrapper.
Just by making a function you're not creating a library. Sometimes I find DOM API verbose too. Nevertheless the fix does not need to be a interface like jQuery to completely hide DOM API under another interface. It may be enough to extend the HTMLElement prototype a bit or write a function to "compress" the code a bit and make it more readable.
Have you seen what passes for a library on npm?
You lost me here. Anybody extending standard objects cannot be taken seriously.
Also, to be clear, I'm suggesting adding new methods to DOM object prototypes, not changing behavior of existing methods.
So, you don't like the polyfill, created to the specification. Fine, but depending who you target, you might not need it. Plenty of modern browsers have good support.
> And even then. You need to encode params manually.
Or use the Request constructor.
> And of course no middleware, so for special decoding or repeating headers, you end up writing a wrapper.
Request constructor will let you handle the headers quite nicely.
Yes, it is.
> It's a dozen lines, not a thousand
A polyfill can be any size, but there's no size minimum to be a library.
A polyfill is a short snippet to implement a missing feature. Notably almost all recent additions to JS and DOM have been designed to be polyfillable where possible. Generally that means under a thousand lines, by the way.
A library in this context means a set of functionality built on top of the platform, like jQuery, with its own API, etc. "Use a library" and "use a polyfill" are not the same advice.
A polyfill is not a library.
Um what? jQuery is huge. You won't possibly use everything in it.
curious as to why you think this? fetch is pretty convenient to use. We created our own wrappers around it, but that basically just consists of ajax = (url) => fetch(url).then(res => res.json())
Or you can use the few ko of jQuery.
Now bundling it with the rest of your JS, that's indeed a mistake.
The CSS file is also nearly 1 Mb.
It's just a simple website with some forms.
They have 2 developers working on the site, a scrum master, a project manager and 2 testers but somehow they can't find the time to find out which legacy code they can remove.
It's only after I pointed out that they have an exceptionally high bouncerate on their (expensive) Adwords traffic and the slowest pageload time of all their main competitors that I managed to get some priority to optimize their site.
Serious question: are there any tools that can scan a full website for unused code and unused CSS?