I am trying to enable browser leverage caching for my angular5 application. Files serve with apache

Here is the configuration I've added in the vhost

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpg "access 1 year"
  ExpiresByType image/jpeg "access 1 year"
  ExpiresByType image/gif "access 1 year"
  ExpiresByType image/png "access 1 year"
  ExpiresByType text/css "access 1 month"
  ExpiresByType text/html "access 1 month"
  ExpiresByType application/pdf "access 1 month"
  ExpiresByType text/x-javascript "access 1 month"
  ExpiresByType application/x-shockwave-flash "access 1 month"
  ExpiresByType image/x-icon "access 1 year"
  ExpiresByType application/javascript  "access 1 week"
  ExpiresDefault "access 1 month"
<IfModule mod_headers.c>
  <filesmatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf)$">
  Header set Cache-Control "max-age=2678400, public"
  <filesmatch "\.(html|htm)$">
  Header set Cache-Control "max-age=7200, private, must-revalidate"
  <filesmatch "\.(pdf)$">
  Header set Cache-Control "max-age=86400, public"
  <filesmatch "\.(js)$">
  Header set Cache-Control "max-age=2678400, private"

But I am testing my website with https://tools.pingdom.com/ I am getting cache failed error message for the .js ,.css and .png assets.

The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources:


Header for .js

HTTP/1.1 200 OK
Date: Fri, 17 Aug 2018 09:44:03 GMT
Server: Apache/2.4.18 (Ubuntu)
Last-Modified: Thu, 16 Aug 2018 11:25:11 GMT
ETag: "172da-5738bb238dfbb-gzip"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Frame-Options: DENY
Strict-Transport-Security: max-age=631138519; includeSubDomains
Content-Length: 32241
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/javascript
  • What are the response headers you get when requesting one of those resources? Add them to your question. Aug 17 '18 at 9:43
  • @GerardH.Pille updated my question
    – iam batman
    Aug 17 '18 at 9:52
  • Where's the Cache-Control header? Expires missing too. Wrong vhost? mod_expires and mod_headers not loaded. Aug 17 '18 at 10:02
  • mod_expires already loaded Module headers already enabled,vhost is proper
    – iam batman
    Aug 17 '18 at 10:21
  • However, I can able to see from memory cache in the status code in chrome
    – iam batman
    Aug 17 '18 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.