Code to Take advantage of browser cache leaves the site out of the air

2

Well, I'm having a problem getting the blessed "Take browser cache" from PageSpeed Insights. The site I'm doing this is on Wordpress. The entire internet indicates the same code to be inserted into the .htaccess file, either in English or Portuguese, which is as follows:

# 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

But whenever I use this, the site is out of breath, I do not know why this occurs, I used that same code in other sites and it did not stay that way.

Can anyone tell me if there has been any change and this form is no longer working?

    
asked by anonymous 06.05.2017 / 16:44

2 answers

3

The problem is the quotation marks and , this type of quotation marks does not work, it should replace " for both:

<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

06.05.2017 / 19:46
2

I use this code on some websites and it works, test your project, change only the term 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>
    
06.05.2017 / 17:05