Site Analyzer vs mod_pagespeed

I'm going to explain to you how to validate the " cache implementation " by the Site Analyzer tool Whether if you use mod_pagespeed or not on apache in version 2.X. This is not necessarily the goal, but it takes a big part in the rating. And all the other tools will also ask you to validate this parameter. (for the impatient, the solution is at the end of the article).

Paradox of Site Analyzer

Before continuing further on how to succeed, I want to alert you that doing this can slightly degrade your score on Page Speed ​​Insights ... On the home page I lost 20 points on average on mobile and desktop. On the content pages I only have a loss of 5/6 points.

Cache-control the much sought after header

So, to know if you have cache on web resources (html, css, js, etc.) with apache nothing more simple. To do just look at the headers returned by the web server of the website. To see these headers under firefox you can use the extension firebug  via the tab "Network" and clicking on the desired resource: 
Cache-control , is the header your server sends to tell the web browser to keep the file cached. So there are several values ​​that we will look at right away.
  • no-cache: tells the browser to always request the file to the server
  • public: the resource can be cached by all
  • private: same as public except that the resource can not be cached by proxies
  • must-revalidate: the resource you request must be re-uploaded by the browser
  • max-age: it's the time in seconds that your browser will have to wait before going to search the content.
So if your header looks like one of the following examples that means you do not have a cache on this resource:
  • max-age = 0, no-cache
  • max-age = 0
  • no-cache
What we are looking for is something like this: max-age = 3600, public or max-age = 3600, private
To know everything about Cache-Control you can also read this page on Wikipedia: Cache-Control

How to configure Cache-Control on apache?

To do this, you already need the following modules on your apache server: 
  • headers
  • hidden
I will not go back on how to install them on Apaches, that does not seem to me necessary, because very often they are of offices. So that apache uses caching of your browser just add the following lines in the .htaccess file of your file.
<IfModule mod_headers.c>
#Cache of all 
Cache-Control header set "max-age = 600, private, must-revalidate"
#Protected caching for image, CSS and JS 
<FilesMatch resources. (Ico | jpe? G | png | gif | swf | css | gz | js | js? Ver = * | css? Ver = *) $ " > 
Cache-Control header set "max-age = 2592000, public" 
</ FilesMatch>
#Hidden HTML resources (the famous ones!) 
<FilesMatch ". (Html ​​| htm) $"> 
Cache-Control header set "max-age = 7200, public" 
</ FilesMatch>
</ IfModule>
Once you add these lines to your .htaccess file, refresh your site's page and see what firebug tells you about the headers. Logically everything should be good!

Mod_pagespeed cache-control for HTML, PHP files

So, in my first test of mod_pagespeed I was happy. But when I was asked the challenge to validate the site on Site Analyzer , I was a little disappointed ... I also spent 3 or 4 hours to find a solution, I scoured the net but found nothing ...
The real concern is that all my resources were well cached, css, js etc. But the HTML page itself is not ... While I had everything it did, at least I thought so, in my .htaccess to have this value.
First, it was missing the little magic lines that I showed you before. But above all I had a setting to activate on mod_pagespeed which made obsolete all possible configurations that I could do in my .htaccess.
So to validate the setting up of cache under Site Analyzer with mod_pagespeed, do not activate the following option:
AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text / html
You must comment on the line in the mod_pagespeed configuration file . Attention can only be disabled from the configuration file. So if ever your host has activated you are blue ... Hoping this article helps you!

Related Posts

Post a Comment

Subscribe Our Newsletter