Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expires headers do not work

I tried a couple of approaches to get images and other resources to have an expiration date, but none seem to work accourding to http://www.webpagetest.org/

I also installed W3 plugin, still the tool reports the images do not have expires headers set.

I also included the following code in my htaccess:

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A300
ExpiresByType application/x-javascript A3600
ExpiresByType text/css A3600
ExpiresByType image/gif A3600
ExpiresByType image/png A3600
ExpiresByType image/jpeg A3600
ExpiresByType text/plain A300
ExpiresByType application/x-shockwave-flash A3600
ExpiresByType video/x-flv A3600
ExpiresByType application/pdf A3600
ExpiresByType text/html A300
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

This seems to be a common problem, and I have seen many questions about this, but couldn't find an answer.

Is the problem in the testing tool or on my server? How can I find out?

like image 911
user1721135 Avatar asked Jun 12 '13 06:06

user1721135


People also ask

HOW use expired header in HTML?

The expires header is an HTTP header that indicates whether it is possible to obtain information on request from the browser cache or if you need to access the server since the page option in the cache is already outdated. This header contains the date and time until the page is available in the browser cache.

Should I add expired headers?

Adding Expires Headers is important to reduce HTTP requests which reduces the time it take for the server to communicate with the browser. It also allows your users to reuse the cache files that have been stored in the browser to reduce the amount of files they need to download.

What is expired response header?

The Expires HTTP header contains the date/time after which the response is considered expired. Invalid expiration dates with value 0 represent a date in the past and mean that the resource is already expired.


Video Answer


2 Answers

I had the same kind of problem. It seems (some) validators, like YSlow, don't succeed until the expires dates are on value 31536000.

Here's a full W3 Total Cache htaccess: http://pastebin.com/wegK3jD6.
It worked for me, you might as well give it a shot.

Note that the pastebin doesn't contain the WordPress htaccess content

like image 59
Mike Madern Avatar answered Oct 23 '22 15:10

Mike Madern


The answer for me was enable expires module.

a2enmod expires
systemctl restart apache2

Answer by: Southparkfan in https://www.digitalocean.com/community/questions/how-to-setup-expire-headers-on-apache

So this code will work in apache server conf

<IfModule mod_expires.c>
    ExpiresActive on
    ExpiresDefault "access plus 1 month"
    ExpiresByType text/html "access plus 15 days"
    ExpiresByType image/gif "access plus 1 months"
    ExpiresByType image/jpg "access plus 1 months"
    ExpiresByType image/jpeg "access plus 1 months"
    ExpiresByType image/png "access plus 1 months"
    ExpiresByType text/js "access plus 1 months"
    ExpiresByType text/javascript "access plus 1 months"

    ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
    ExpiresByType font/ttf "access plus 1 year"
    ExpiresByType font/otf "access plus 1 year"
    ExpiresByType font/woff "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
</IfModule>

Hope that helps

like image 21
Emanuel Avatar answered Oct 23 '22 14:10

Emanuel