ph3nx
ph3nx

Reputation: 1046

JavaScript expires headers can't be set to 12 months

I'm trying to make my website load faster. I used the tool YSlow to analyze the website and check for some improvements. My first step is to cache static files. Therefore I want to set the expires headers for a javascript file, but it doesn't work. I included the javascript in HTML like this:

<script type="text/javascript" src="//a.ph3nx.com/b.js"></script>

Then I changed my Apache2 httpd.conf file like this:

ExpiresActive On
ExpiresDefault "access plus 1 minutes"
ExpiresByType text/javascript "access plus 12 months"

The problem is that the javascript file still has a expiring date of 1 minute. I hope you can help me, thank you!

Solution:

ExpiresByType application/javascript "access plus 12 months"

Upvotes: 5

Views: 573

Answers (1)

StasGrin
StasGrin

Reputation: 1808

Try such code:

  ExpiresByType text/javascript "access plus 12 month"
  ExpiresByType application/x-javascript "access plus 12 month"
  ExpiresByType application/javascript "access plus 12 month"

Also u can cache your files using .htaccess:

  <FilesMatch "\.js$">
  Header set Cache-Control "max-age=172800, public, must-revalidate"
  </FilesMatch>

Upvotes: 2

Related Questions