Code to Leverage Browser Cache Leaves the Site Offline

Asked

Viewed 1,177 times

2

Well, I’m having a problem getting the blessed "Enjoy Browser Cache" out of Pagespeed Insights. The site I’m doing this for is Wordpress. The entire internet indicates the same code to be inserted into the . htaccess file, either in English or Portuguese, which is the following:

# COMEÇA BROWSER CACHE

<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”
ExpiresByType application/javascript “access plus 1 month”
ExpiresDefault “access plus 2 days”
</IfModule>

# TERMINA BROWSER CACHE

It’s just that whenever I use this, the site is off the air, I don’t know why it happens, I’ve used this same code on other sites and it’s not like this.

inserir a descrição da imagem aqui

Would anyone know if there’s been any change and that way isn’t working anymore?

2 answers

3


The problem is the quotes and , this type of quotation marks does not work, should be replaced by " for both of us:

<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"
ExpiresByType application/javascript "access plus 1 month"
ExpiresDefault "access plus 2 days"
</IfModule>

About Pagespeed Insights

About Etag

  • 1

    That’s right, buddy. Thank you very much.

2

I use this code on some websites and it works, test your project, change only the timeframe of each item that may be different for you !

#Força a utilizar Cache-Control e Expires header
<IfModule mod_headers.c>
    Header unset ETag
</IfModule>
FileETag None
<IfModule mod_expires.c>
    ExpiresActive on
    ExpiresDefault "access plus 1 month"
    ExpiresByType text/cache-manifest "access plus 0 seconds"
    # HTML
    ExpiresByType text/html "access plus 0 seconds"
    # DATA
    ExpiresByType text/xml "access plus 0 seconds"
    ExpiresByType application/xml "access plus 0 seconds"
    ExpiresByType application/json "access plus 0 seconds"
    # FEED
    ExpiresByType application/rss+xml "access plus 1 hour"
    ExpiresByType application/atom+xml "access plus 1 hour"
    # FAVICON
    ExpiresByType image/x-icon "access plus 1 week"
    # MEDIA: IMAGES, VIDEO, AUDIO
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType video/ogg "access plus 1 month"
    ExpiresByType audio/ogg "access plus 1 month"
    ExpiresByType video/mp4 "access plus 1 month"
    ExpiresByType video/webm "access plus 1 month"
    # HTC files
    ExpiresByType text/x-component "access plus 1 month"
    # WEBFONTS
    ExpiresByType application/x-font-ttf "access plus 1 month"
    ExpiresByType font/opentype "access plus 1 month"
    ExpiresByType application/x-font-woff "access plus 1 month"
    ExpiresByType image/svg+xml "access plus 1 month"
    ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
    # CSS / JS
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType application/x-javascript  "access plus 1 year"
</IfModule>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.