Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leverage browser caching - updates not working

Tags:

.htaccess

web

I am using Google page speed insights to improve the performance but no matter what I do I can't get the 'leverage browser caching' to disappear.

I have modified the htaccess file as described on several online articles and added every combination I can. In page insights it's complaining about CSS/PNG/JS/JPG files.

# Expires Caching Start #
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access 2 day" 
ExpiresByType text/html "access 2 day" 
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month" 
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresDefault "access 1 month"
ExpiresByType text/x-javascript "access plus 1 month"  
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType text/x-javascript "access 1 month"
</IfModule>
# Expires Caching End # 
like image 753
connersz Avatar asked Apr 20 '16 17:04

connersz


People also ask

What does leverage browser caching mean?

To leverage your browser's caching generally means that you can specify how long web browsers should keep images, CSS and JS stored locally. That way the user's browser will download less data while navigating through your pages, which will improve the loading speed of your website.

How do you fix a long cache lifetime can speed up repeat visits to your page?

Unfortunately there is no quick answer to that question, and it depends on what you are doing. In the case of static assets (js, css, images) that never change, setting the max-age to a year of more is perfectly fine.


1 Answers

You seem to be missing you plus in "access plus 1 month" in many lines. Default should be your second line for readability

Here is part of the h5bp template:

ExpiresActive on
ExpiresDefault                                      "access plus 1 month"
ExpiresByType text/css                              "access plus 1 year"
ExpiresByType text/html                             "access plus 0 seconds"
ExpiresByType application/javascript                "access plus 1 year"
ExpiresByType application/x-javascript              "access plus 1 year"
ExpiresByType text/javascript                       "access plus 1 year"

... https://github.com/h5bp/html5-boilerplate/blob/master/dist/.htaccess

like image 65
user3802077 Avatar answered Nov 05 '22 07:11

user3802077