How to Get 100/100 Google Page Speed Score with Middleman and Nginx
elliotec.com
elliotec.com
I never understood why Google doesn't fix this. I want to use Google Analytics but their own tool penalizes me for it because it gets unproperly cached on Google's own servers? That's just stupid.
So it’s not good for speed
> Even Google's own tag manager/analytics scripts lowers your page speed score
Well these don’t exactly speed up loading your page.
Also, no need to put assets in a different domain anymore ( limit on loading resources per domain simultaneously)
It's even considered harmful since extra domains means extra dns lookups which could take quite a while.
I agree on http 1.1. Sorry that you downvoted on a lack of knowledge ;)
Talk about diminishing returns here.
Source: We've got an Angular 1 SPA as a website that despite maxing out in the 70s for page speed (because we can't get rid of 700k of blocking JS) still ranks like hell, because we do all the rest right.
This is incorrect. Static assets are often the source of many problems, due to poor caching headers for static assets, missing gzip encoding, unoptimized images, etc. The time it takes for the backend to return a response will usually result in more overall savings in load times, but it's astounding just how inefficient frontend choices can be. It's not "micro-optimizing" to focus on improving the frontend instead of only focusing on the backend.
Some optimizations can backfire. Adding async to the external JS is a great tip.. unless you have dependencies between your different scripts (i.e. you need one to be loaded before the other one gets executed)
The library is at https://github.com/skorokithakis/django-cloudflare-push if anyone wants to use it. It's slightly misnamed, as it supports any server that uses the Link header for push, not just CloudFlare.
That does not seem to be a good tradeoff, especially on mobile.
I still don't see how HTTP/2 Push is solving any real-world problems [1] besides Google being able to push ads so that it counts as an impression even if the client blocks ads.
[1] I don't count the slightly faster initial page load since I'm getting that junk on every page load via push even if I already have it, so I'm paying with my data allowance. If you want your site to load fast, just fix your goddamn bloat.
https://stackoverflow.com/questions/29352282/does-the-browse...
And this feature shows as merged into ff56:
https://bugzilla.mozilla.org/show_bug.cgi?id=1367551
Cache digests are about the client telling the server what items it has cached so push doesn't even start, not about canceling pushes.
Why on earth when they introduced it they didn't add a way to tell the browser the order of execution ? Or may be it exists and I haven't heard about it ?
If you’re using S3+CloudFront, it’s not dirt cheap.
Traffic at AWS is so expensive, at any scale it’s cheaper to roll your own. Significantly.
(For traffic in the EU, that is, in other regions traffic tends to be a lot more expensive)
Also, if there is an issue with either of these it's far easier for me to justify downtime to a client by saying "Amazon us-east is down, here's Amazon's status page" then trying to explain who OVH is.
S3 + Cloudfront + ad hoc Lambdas is a far far easier cost benefit ratio when it comes out what my time is worth. To each their own :)
In a previous startup I was CTO and founder for, I used a gentoo and managed everything possible by myself. This was not especially costly in time because I was already used to it and efficient, and we managed that way to stay for 3 years with 70€/mo in infrastructure cost. This has its advantages too :)
For example, I use a CDN for some of my assets, except for users in the EU.
It turns out, for users in the EU I can get faster speeds with my own systems, for almost two orders of magnitude difference in traffic pricing.
If a large amount of your users happen to be in such a region, it might even make sense to use no CDN at all.
What I was most interested in technically is the part about 'Prioritize visible content'. You talk about "loading third party scripts later, and generally keeping the above-the-fold content small and fast". From this I make out that you do not load images below the fold, etc. I was wondering what you do technically to make this happen. Also, how would you load fonts after the first paint, etc. Also, from what I remember, when you inline your CSS you make caching the CSS separately from the HTML impossible. What would you do when you want to have a quick first paint, but also want to leverage having CSS in its own file?
https://www.google-analytics.com/plugins/ua/linkid.js (60 minutes)
https://www.google-analytics.com/analytics.js (2 hours)I personally find that most of the workarounds for this are usually more technically offensive than living with a marginally lower score on this often somewhat arbitrary test.
location /analytics.js {
proxy_pass https://www.google-analytics.com;
expires 1d;
}Note I'm not actually trying to use the API, I just want to run the tool from https://developers.google.com/speed/pagespeed/insights/
I always get pinged for GA and for Google Fonts. Not sure this makes any sense. Kind of detracts from the tool in general, actually.
Context is key. Nobody should be shooting for a perfect 100 in any situation where a barebones static HTML document won't suffice. So if you have to make DB calls to create the HTML document, or are reasonably delivering a nice user experience (e.g., a custom font), then you should not be scoring 100.
With that being said, you are still doing great for what you are delivering if it's non-static content with fonts and can get to at least 80 / 100.
Interesting thing is that the score fluctuates without me doing any changes.
Trying to explain the page speed tool is just a 'rough guide' and that a website always has to be some kind of compromise between speed, functionality and design falls on deaf ears because 'google' is, well, 'google'.
It doesn't make a noticable difference, but it's fun.
Gzip compression benefits taper off in benefit after the "7" setting, IIRC. Brotli at higher settings compresses better, but you'd want to do it static as opposed to on the fly (at higher/highest settings)
I'm curious if brotli's decompression is still fast on high compression levels. This is the case for gzip IIRC.
https://blog.codinghorror.com/zopfli-optimization-literally-...
https://blogs.akamai.com/2016/02/understanding-brotlis-poten...
one more: https://medium.com/front-end-hacking/reduce-your-javascript-...
Yes, it's optimized for fast decompression. Compression, on the other hand, is comparatively expensive. This trade-off makes Brotli very interesting for static assets.
OP thanks for the great article.
Also it often gives crazy advices, for example something like "embed CSS code necessary to display the top of the page, right into the page". Not only it is difficult to implement, (what exactly is "the top of the page"? how to understand what part of the code is necessary? what if the user scrolls the page down while loading?), it will make the pages larger and doesn't allow browser to cache embedded CSS. So you have to invest a lot of time and your page will probably load slower as a result.
But at the same time this script doesn't notice obvious things. For example, it never advices to remove or replace web fonts although web fonts are heavy, can cause problems with rendering text (they can lack glyphs, for example cyrillic or CJK characters) and web fonts block text rendering. And they are really unnecessary in most cases because builtin system fonts usually look better at small sizes (at least on Windows).
Also it never advices to remove ads althogh ads often cause high CPU and memory consumption. Why is that I wonder.
The tool always requires to move JS scripts to the bottom of the page. But is it always the best idea? I think in most cases it is not. For example, if you have a button with an onclick handler, it will give a JS error if the button is clicked before the scripts in the bottom of the page have loaded (the problem of dead JS controls). And if you put a small JS script at the top of the page, there will be no error. And what if you have a SPA? In this case the earlier you start to load the scripts the sooner the user will be able to see the data.
Also it always recommends to use a CDN which is not always good idea. For example, if you have a site in Russia or China and move your static files to CDN then it might be farther from the user than your server and even worse, it can get blocked so your site won't even be loading. Adding a CDN often doesn't make performance any better but reduces the reliability and increases your hosting bill.
So Google's script might help you in identifying problems with your site but you should not ever blindly trust any of the recommendations. Please leave client side optimization to people who have expertise in this area.
By the way I had to lessen the image quality to get a better score (and foolow other useless or even harmful recommendations) because our management believes that the score given by this tool (it is Google's official tool after all) affects SEO rankings and obviously they are more important than image quality.
The article says "Then, inline your CSS and JS instead of making external resource calls to them." and this is actually what makes your page heavier.
> Finally, I was having a lot of trouble getting the Google Analytics script on my site to not be render-blocking
It is easy. Don't understand what was the trouble.
it often advices to compress images and even suggests to download "optimally" compressed versions
Compressing images is useful, and this advice can be beneficial – though I'm sure it's more effective to optimise them yourself rather than relying on the Google-generated versions.
"embed CSS code necessary to display the top of the page, right into the page".
This is good advice. For larger sites with more extensive stylesheets, this approach allows the initial 'above-the-fold' to be rendered better before the full stylesheet is loaded. Just because it doesn't hit every case – like when users scroll during load – does not render it ineffective. It's also neither difficult to implement, nor does it add enough load time to pages to be a practical issue (unless you're inlining 100kB of text, in which case – rethink your stylesheet!)
For example, it never advices to remove or replace web fonts
It would be a bit silly to do so; web fonts are added on purpose, and advising that they be removed is pretty useless advice, along the lines of "you can speed up your website by removing images". It would be nice if the tool supported analysis of web font use though, such as testing to see if particular styles are used, or if the font could be effectively subsetted.
Also it never advices to remove ads althogh ads often cause high CPU and memory consumption. Why is that I wonder.
Again, it would be useless information to tell someone who has deliberately added advertising to their website to remove it.
The tool always requires to move JS scripts to the bottom of the page. But is it always the best idea? I think in most cases it is not.
Yes, it is – either that, or loading the scripts deferrably or asynchronously.
it will give a JS error if the button is clicked before the scripts in the bottom of the page have loaded
This is only the case if you write bad Javascript – binding to DOM elements and their events should be done asynchronously.
And what if you have a SPA? In this case the earlier you start to load the scripts the sooner the user will be able to see the data.
If you have an SPA, then either there is no real markup on the page (and the difference will be minimal) or you are pre-rendering it, and the content will be visible anyway.
Also it always recommends to use a CDN which is not always good idea.
Using a CDN is almost always a good idea unless you have a very specific reason not to do so.
So Google's script might help you in identifying problems with your site but you should not ever blindly trust any of the recommendations. Please leave client side optimization to people who have expertise in this area.
I would say this much is obvious – it's a tool, and like any others, experienced professionals can use it to make appropriate decisions. It can help with that.
SEO rankings and obviously they are more important than image quality.
The unfortunate thing is that they probably are!