Web Page Performance Death by a Thousand Tiny Cuts
metroize.com
metroize.com
So before you dive into micro-optimising JS, consider whether you even need all that JS at all. Of course this is unavoidable for certain sites which must be app-like, but if plain HTML and CSS is sufficient, then you will have effectively optimised the JS to its ultimate end. (Don't serve CSS with thousands of rules which you don't use either.)
For example, reddit frontpage (which doesn't have much ad) has 6 additional iframes. It makes 76 requests (775 Kb) while loading of which only 15 (taking 335 Kb) belong to reddit domains, other are third-party. So by just disabling third-party services (you can do it on the browser side) they can make the page two times smaller.
Techcrunch has 19 additional iframes. It makes 273 requests (of which approximately 190 are third-party) and loads 2.1 Mb of data (of which approximately 1.1 Mb account for third-party domains). Opening single techcrunch page is like opening 20 new tabs in your browser.
And as a site owner you cannot optimize your ad provider scripts. Yet you can "optimize" them out at a browser side as a user.
Instead of blaming everything on javascript or jquery people should look at network tab in developer tools.
You can, if you directly negotiate ad contracts.
They still might have dumb code and overly fancy animations of course.
> not using image sprites
sprite_images filter: https://developers.google.com/speed/pagespeed/module/filter-...
> not using a cookieless domain for images and other static content
MapRewriteDomain directive: https://developers.google.com/speed/pagespeed/module/domains...
> not using a CDN
Once you have a (pull) CDN set up, mod_pagespeed can rewrite your resources onto it with the same MapRewriteDomain directive.
> blocking javascript - worse if it’s in the head
defer_javascript filter: https://developers.google.com/speed/pagespeed/module/filter-...
> not minifying your javascript and CSS
rewrite_javascript: https://developers.google.com/speed/pagespeed/module/filter-...
rewrite_css: https://developers.google.com/speed/pagespeed/module/filter-...
> not optimizing caching policies
mod_pagespeed automatically longcaches everything: https://developers.google.com/speed/pagespeed/module/filter-...
> not gzipping your content - most if not all popular web servers support some type of compression
mod_pagespeed automatically enables gzip compression
About half of these are enabled by default (minifying css and js, optimizing caching, turning on gzip) and the rest need to be configured.
(If I were making the list I would also have included resource combining for css and js, which mod_pagespeed does by default.)
HN is not bad with 91/100: https://developers.google.com/speed/pagespeed/insights/?url=...
Compared to PageSpeed home (unfair) 64/100: https://developers.google.com/speed/pagespeed/insights/?url=...
;-)
PS: The FAQ source code link points Google Code (instead of GitHub: https://github.com/pagespeed/mod_pagespeed)
What kind of abusive management structure has this guy thinking he has to work for performance issues on his own time? I shudder to think what company he's working for or what manager has instilled such a sense in him and I truly feel sorry for him that he thinks this way.
Now if the company demanded certain perf issues be resolved ahead of shipping and didn't provide company time for it, that would be a different matter and I'd agree with you.
1. http://mrale.ph/blog/2014/02/23/the-black-cat-of-microbenchm... 2. http://mrale.ph/blog/2014/12/24/array-length-caching.html
And minifying doesn't make sense if you gzip your content -- you just add an extra processing step for little to no benefit at all.
- all the various browsers
- all the various network speeds (3G, 4G, DSL, Fiber, etc)
- all the different devices
There is value in having some set of high level guidelines or best practices, which of course, can be argued over.- Not combining javascript or css files where it makes sense
- Not using lazy loading for pages with lots of images
> not minifying your javascript [...]
If you designed properly with progressive enhancement, the page will at least work while the javascript is still loading. For most situations it's fine if the fancier features are not immediately available as long as the page itself is readable immediately.
> third party javascript partners
Aka shady ad/tracking networks. This isn't a technical problem.
1. apache gzip rules
2. apache expires headers
3. smaller images with ImageAlpha/ImageOptim
4. javascript to bottom of the page
Simple things to make your webpage load faster.... other than a div that says "Loading..." for half a second to a second. Yeah, not great, but it's an app (HUGE government form), not a marketing flyer.
(apologies to those who already mentioned concatenation, but I thought it worth mentioning what a bonus "cache headers PLUS concatenation" is)
The modern web is perfectly fine and fast, it's just abused to hell by all the extra "design", images, ads, videos, analytics, etc. Just keeping it simple would solve more problems than anything else.
However a good 75% of it is unnecessary and because of bad business management rather than technical reasons. There are better ad networks and analytics services, combined with better site architecture and code, that can make a big impact if the publishers cared to do it.
The CDN might help the ping time of that request, but on a low-bandwidth device, 4 MB is still 4 MB no matter what server it's coming from.
They have a bunch of similar features: https://www.cloudflare.com/features-optimizer/
I don't understand why a 4 mb image would be likely cached. The problem is mostly custom sites with massive assets, not your copy of jquery that's probably heavily redundant.
They aren't magic though and still require optimization at some stage to be optimal for everyone. This can be during the development process of some CDNs like CF have front-end optimization settings to reduce images dynamically, inline JS, minify content, etc.
Using both dev-time and run-time optimization can greatly help performance.
"What about other areas and under-the-covers code that just
needs rework? Just do what I do, and work on it on your own
time."
Yeah because doing unpaid work for your company is the way to go.Get a life and learn to leave work at work.
It's not the developer's fault if the manager is not dedicating enough man-hours to finish something, only to find out later on that messy code eats up many more man-hours than having it written cleanly the first time with much lower maintenance costs later on.
If developers don't man up and let the managers crash and fail for it, they will be supporting greed and exploitation in the workplace and probably make it worse.
I think its a bit rude for you to suggest someone who brings some work home has no life. Many developers are passionate about their job, they love learning and most importantly they love a good challenge. You don't stop thinking about a challenge at work as soon as the clock hits 5.
Its also a shane that the former is what most people find themselves in. A means to an end in a world that isnt very kind to everyone.
There are those that spend off-time programming, just not for their employer's tasks.
The quid-pro-quo of employee-employer loyalty is largely gone these days, so it's not unreasonable to only work the hours you're compensated for.
I'm using the term loyalty for lack of a better term. There was a time when employees would often go above and beyond for their employers, because the reverse was also often true. Roughly, the shift away from the "lifetime employment" model.
Things like:
- Somewhere in the 1980's, when layoffs started to happen even in relatively financially healthy companies
- The move from pensions to 401k's
- The shift of a higher percentage of healthcare costs to the employee's portion
- More focus on hiring outsiders into higher level positions, versus training/placing internal candidates
Specifically, I might be incented to occasionally "work for free" if I thought the company would, for example, not lay me off during a particularly rough financial period.
I think that people who work on their employer's projects during their own time are unimaginative - they could be writing their own software for their own benefit but they instead choose to make their employer rich and not see any of that compensation themselves.
This is of course assuming you're drawing a salary from the company and you're not mostly paid in equity, in which case putting in free hours might make more sense if you can make the product profitable.
However I am curious how others feel about learning on your own time. I do a fair bit of that (and the company often benefits as a result) but there is hardly a set line between working and learning in our line of work, its definitely a continuum.
This is much more rewarding than doing unpaid work for your boss on code that will probably never see the light of day anyway.
There is a lot to learn by collaborating with other people on code projects of this nature.
I love programming and working out how to solve a problem, but if it something my employer makes money off then they can give me the time to fix it. In my own time, I work on my own projects and challenges. Be it the automation bot I have running in my house or the games that me and a few friends create.
Doing work stuff in your own time can - and does - lead to the expectation that you'll do it more, so the business accounts for that and will possibly even count it against others that don't do it.
I think it's more accurate to assume that a company/team doesn't have the ability to write it cleanly until proven otherwise, and a manager/developer blame game signals the company's lack of this ability (this says nothing about an individual manager or developer's ability when taken alone or in a different context - due to multiplicative factors, a team is often much better or much worse than the sum of its members)