Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess leverage browser caching for images and css

I am trying to create a htaccess file for my website and the pageSpeed insights has shown that there are images and one css file without expiration.

I am not sure where to start with this or how to do it, I have this code from a tutorial online and was wondering if this would be enough to work.

<IfModule mod_expires.c> ExpiresActive On ############################################ ## Add default Expires header ## http://developer.yahoo.com/performance/rules.html#expires <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> ExpiresDefault "access plus 1 year" </FilesMatch> </IfModule> 

Or does this code do what I need it to do?

Thanks

like image 310
Sam Avatar asked Oct 23 '12 11:10

Sam


People also ask

How do I leverage my browser cache?

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 I fix the leverage browser caching warning in HTML?

To fix the leverage browser caching warning with WP Rocket, all you have to do is install and activate the plugin. That's it. For more details, see our guide on how to properly install and setup WP Rocket in WordPress. WP Rocket will automatically enable browser caching and modify your .

How do I fix leverage browser caching in WordPress?

Fixing Leverage Browser Caching in WordPress with the W3 Total Cache can be done by following the steps listed below: Download and install the W3 Total Cache WordPress plugin. Navigate to General Settings and select Enable Browser Cache. Click save and navigate to Browser Cache Settings (top of the page)


1 Answers

try something like

<IfModule mod_expires.c>    ExpiresActive On   ExpiresDefault "access plus 1 seconds"   ExpiresByType text/html "access plus 1 seconds"   ExpiresByType image/x-icon "access plus 2592000 seconds"   ExpiresByType image/gif "access plus 2592000 seconds"   ExpiresByType image/jpeg "access plus 2592000 seconds"   ExpiresByType image/png "access plus 2592000 seconds"   ExpiresByType text/css "access plus 604800 seconds"   ExpiresByType text/javascript "access plus 86400 seconds"   ExpiresByType application/x-javascript "access plus 86400 seconds" </IfModule> 

or

<FilesMatch "\.(?i:gif|jpe?g|png|ico|css|js|swf)$">    <IfModule mod_headers.c>     Header set Cache-Control "max-age=172800, public, must-revalidate"   </IfModule>  </FilesMatch> 
like image 81
NullPoiиteя Avatar answered Sep 23 '22 22:09

NullPoiиteя