Elxis CMS Forum

Support => General => Topic started by: Blacksoll on April 26, 2018, 09:36:27

Title: PageSpeed: Leverage browser caching
Post by: Blacksoll on April 26, 2018, 09:36:27
Guidelines for setting expiries from gtmetrix.com (http://gtmetrix.com):

Code: [Select]
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##

Should i add this to .htaccess or not ? If yes, where do i add it ?
Title: Re: PageSpeed: Leverage browser caching
Post by: datahell on April 26, 2018, 14:50:27
The problem with the analysis is that such settings can create some issues.
To undersstand the problem I will write you an example.
You have your template file named "sample.css". This is a static file that never changes, right? So in your htaccess you tell the browser to cache this file for 1 year. Some day you decide to make a change in this file to fix a problem, or to add a new css declaration, etc. This change will NEVER be seen by your site visitors untill a year is passed (except if they clear their browser cache). So, you will think that you have updated the file but it will be updated only for new visitors. Undestood? To fix this problem you will have to remove the expire setting from htaccess.

Especially for javascript files the problem can be much bigger. Consider what will happen if you cache a js library that controls a js calendar. A new version is released for the calendar, you install the update, your html is updated for the customers but not the javascript file. Result? The calendar doesnt work any more, or semi-works (best case).

I personally, also deagree with the defer javascript parsing (loading javascript at the bottom of the page). And other things. But this is just my opinion...
Title: Re: PageSpeed: Leverage browser caching
Post by: Blacksoll on April 26, 2018, 22:49:30
Since i'm just an amateur and at my free time i mess around with my website the opinion of a professional always matters.....

I'll stay then with my only modification for file tags. I saw some improvement with this at speed tests

Code: [Select]
<IfModule mod_headers.c>

Header unset ETag

<filesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
<filesMatch "\.(css)$">
Header set Cache-Control "max-age=604800, public"
</filesMatch>
<filesMatch "\.(js)$">
Header set Cache-Control "max-age=216000, private"
</filesMatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "max-age=420, private, must-revalidate"
</filesMatch>
</IfModule>
FileETag None
Title: Re: PageSpeed: Leverage browser caching
Post by: datahell on April 28, 2018, 10:05:42
Speed improvements were absolutely necessary in the past but not so much now. Internet connections are much faster now-days and hosting companies provides much more bandwidth to the hosting packages (even unlimited). OK, it is good the site to load fast, but if this may create a problem then don't do it. THIS IS MY PERSONAL OPINION, others may disagree.