Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

header expire on javascript files not working

I can't get the expire header on JS files to work properly.. It works fine on eg CSS files!?

Could anybody tell me what Im doing wrong? :(

htaccess

ExpiresActive on
ExpiresDefault A0
ExpiresByType image/gif A29030400
ExpiresByType image/jpeg A29030400
ExpiresByType image/png A29030400
ExpiresByType text/css A29030400
ExpiresByType text/javascript A29030400
ExpiresByType application/x-javascript A29030400

header on CSS file

Cache-Control   max-age=29030400
Connection  Keep-Alive
Date    Sun, 14 Oct 2012 12:06:45 GMT
Etag    "be-4cbcf2ad48b40"
Expires Sun, 15 Sep 2013 12:06:45 GMT
Keep-Alive  timeout=5, max=97
Server  Apache/2.4.2 (Win64) PHP/5.4.3

header on JS file

Cache-Control   max-age=0
Connection  Keep-Alive
Date    Sun, 14 Oct 2012 12:06:45 GMT
Etag    "1ad-4cc00d069f493"
Expires Sun, 14 Oct 2012 12:06:45 GMT
Keep-Alive  timeout=5, max=99
Server  Apache/2.4.2 (Win64) PHP/5.4.3
like image 568
clarkk Avatar asked Oct 14 '12 12:10

clarkk


People also ask

HOW use expired header in HTML?

Expires Headers are certain lines of code that tell your browser how long it should keep the cached files from your site. You can add Expires Headers by adding a code such as ExpiresByType image/jpg “access plus 1 month” to your site.

What is an expire 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.


2 Answers

(can't comment yet...) I run the following settings and it works.

ExpiresByType text/js "access plus 1 years"
ExpiresByType text/javascript "access plus 1 years"
ExpiresByType application/javascript "access plus 1 years"
ExpiresByType application/x-javascript "access plus 1 years" 

Should work

Cheers Robin

like image 194
Robin Rieger Avatar answered Sep 19 '22 11:09

Robin Rieger


Try wrapping an ExpiresDefault in a <filesMatch tag instead of using ExpiresByType :

<filesMatch "\.(js)$"> 
    ExpiresDefault A29030400 
</filesMatch>
like image 21
Tr1stan Avatar answered Sep 17 '22 11:09

Tr1stan