Fix Google PageSpeed leverage browser caching in htaccess

To optimize browser caching in htaccess, simply add the following code inspired by a Stack Overflow thread [1] in your htaccess file :

#Browser caching
ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/png A2592000
ExpiresByType image/x-icon A2592000
ExpiresByType text/css A86400
ExpiresByType text/javascript A86400
ExpiresByType application/x-shockwave-flash A2592000
#
<FilesMatch "\.(gif¦jpe?g¦png¦ico¦css¦js¦swf)$">
Header set Cache-Control "public"
</FilesMatch>

It will allow you not only to pass the Google PageSpeed Leverage browser caching test, but most importantly to speed up your website access time.

For example, this allowed me to pass the Google PageSpeed [2] test Leverage browser caching [3] (along with Eliminate render-blocking JavaScript and CSS in above-the-fold content [4]) on a website, going up from a score of 51 on mobile (Fig 1) to 72 (Fig 2), and up from 59 (Fig 3) to 79 on desktop (Fig 4).

Fix Google PageSpeed leverage browser caching in htaccess : Fig 1 : Google Page Speed - Score before leveraging browser caching of 51 on mobile
Fig 1 : Google Page Speed - Score before leveraging browser caching of 51 on mobile
Fix Google PageSpeed leverage browser caching in htaccess : Fig 2 : Google Page Speed - Score after leveraging browser caching of 72 on mobile
Fig 2 : Google Page Speed - Score after leveraging browser caching of 72 on mobile
Fix Google PageSpeed leverage browser caching in htaccess : Fig 3 : Google Page Speed - Score before leveraging browser caching of 59 on desktop
Fig 3 : Google Page Speed - Score before leveraging browser caching of 59 on desktop
Fix Google PageSpeed leverage browser caching in htaccess : Fig 4 : Google Page Speed - Score after leveraging browser caching of 79 on desktop
Fig 4 : Google Page Speed - Score after leveraging browser caching of 79 on desktop

Similar articles

Comments (14)

Hazel Hammond, 2018-08-19
Я не знал об этих деталях, пожалуйста, сделайте больше
Traci Reese, 2018-08-19
Простой, понятный и хорошо объясненный, большое спасибо
Yvonne Woods, 2018-08-19
Erstaunlich, jetzt ist es an mir, es zu versuchen!
Dave Ortega, 2018-08-19
Tuyệt, đó chính xác là những gì tôi đang tìm kiếm, bây giờ tôi đã sẵn sàng
Silvia Chavez, 2018-08-19
Thật tuyệt vời, bây giờ đến lượt tôi thử!
Marcos Tyler, 2018-08-19
有一個很好的時間閱讀這些信息,保持良好的工作
Julia Anderson, 2018-08-19
That worked well for me, no need to look any further
David Ward, 2018-08-19
Great site, please keep going
Marie Wright, 2018-08-19
Exatamente o que eu estava procurando, perfeito
Britneyor, 2018-08-19
Sì, questo è quello di cui avevo bisogno
Desightab, 2018-08-19
うわー、それは本当に簡単です、今すぐ試してみましょう
Infernova, 2018-08-19
私は最終的に解決策を見つけたと信じられない、これは長い時間の悪夢だった今解決された
Zabarinil, 2018-08-19
素晴らしいサイトです
civilu6, 2018-08-19
Ajablanarlisi, ma'lumot almashish uchun rahmat

Leave a comment