4

I have implemented resourec expiry with the following set up

<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 application/x-javascript "access plus 1 month"
    ExpiresByType text/javascript "access plus 1 month"
    ExpiresByType application/x-shockwave-flash "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresDefault "access plus 2 days"
</IfModule>

with a2dismod expires, as expected I have no Expires header:

    wget --server-response --no-check-certificate https://sandbox.trinityp3.com/wp-includes/js/jquery/jquery.js?ver=1.12.4
--2018-10-17 07:57:09--  https://sandbox.trinityp3.com/wp-includes/js/jquery/jquery.js?ver=1.12.4
Resolving sandbox.trinityp3.com (sandbox.trinityp3.com)... 52.77.97.226
Connecting to sandbox.trinityp3.com (sandbox.trinityp3.com)|52.77.97.226|:443... connected.
WARNING: cannot verify sandbox.trinityp3.com's certificate, issued by ‘emailAddress=mark@xxx.xxx,CN=sandbox.trinityp3.com,O=Internet Widgits Pty Ltd,ST=Some-State,C=AU’:
  Self-signed certificate encountered.
HTTP request sent, awaiting response... 
  HTTP/1.1 200 OK
  Date: Tue, 16 Oct 2018 18:57:10 GMT
  Server: Apache/2.4.10 (Ubuntu)
  Last-Modified: Tue, 06 Sep 2016 02:32:13 GMT
  Accept-Ranges: bytes
  Content-Length: 97184
  Vary: Accept-Encoding
  Access-Control-Allow-Origin: *
  Referrer-Policy: 
  Cache-Control: max-age=604800, public
  Keep-Alive: timeout=5, max=100
  Connection: Keep-Alive
  Content-Type: application/x-javascript

with a2enmod expires however I do get a 1 year expires response

  wget --server-response --no-check-certificate https://sandbox.trinityp3.com/wp-includes/js/jquery/jquery.js?ver=1.12.4
--2018-10-17 08:01:26--  https://sandbox.trinityp3.com/wp-includes/js/jquery/jquery.js?ver=1.12.4
Resolving sandbox.trinityp3.com (sandbox.trinityp3.com)... 52.77.97.226
Connecting to sandbox.trinityp3.com (sandbox.trinityp3.com)|52.77.97.226|:443... connected.
WARNING: cannot verify sandbox.trinityp3.com's certificate, issued by ‘emailAddress=mark@xxx.xxx,CN=sandbox.trinityp3.com,O=Internet Widgits Pty Ltd,ST=Some-State,C=AU’:
  Self-signed certificate encountered.
HTTP request sent, awaiting response... 
  HTTP/1.1 200 OK
  Date: Tue, 16 Oct 2018 19:01:27 GMT
  Server: Apache/2.4.10 (Ubuntu)
  Last-Modified: Tue, 06 Sep 2016 02:32:13 GMT
  Accept-Ranges: bytes
  Content-Length: 97184
  Vary: Accept-Encoding
  Cache-Control: max-age=604800, public
  Expires: Wed, 16 Oct 2019 19:01:27 GMT
  Access-Control-Allow-Origin: *
  Referrer-Policy: 
  Keep-Alive: timeout=5, max=100
  Connection: Keep-Alive
  Content-Type: application/x-javascript

I have also run grep to find any other expires statements, but there are none.

After adding ExpiresByType application/x-javascript the problem still persists. Could there be a conflict with deflate?

ubuntu@sandbox:/etc/apache2$ grep -r application/x-javascript *
mods-available/deflate.conf:        AddOutputFilterByType DEFLATE     application/x-javascript application/javascript application/ecmascript
sites-available/710-tp3-au-www-sandbox.conf:    ExpiresByType     application/x-javascript "access plus 1 month"
sites-available/710-tp3-au-www-sandbox.conf:    ExpiresByType     application/x-javascript "access plus 1 month"
jdog
  • 121
  • 7
  • 29
  • Try changing "ExpiresByType image/jpg "access plus 1 year" (and so on) by "ExpiresByType image/jpg "access plus 2 year" and see if you get 2 years response? – bgtvfr Oct 19 '18 at 09:44
  • @bgtvfr suggestion is a starting point; I would change *all* the "plus one year", so that you do not have any "plus one year" at all in your config file. Make them all different (3 days, 4 days, 5 days, etc.) If you get one of them you'll know which one it is. If you continue getting one year, it can be because you have not restarted (or maybe not the right process), because the file is not the right file, or maybe because it is being overridden (maybe your grep did not find the overriding file). – Law29 Oct 21 '18 at 10:03
  • Thanks @law29. I have changed them and also removed the surrounding – jdog Oct 23 '18 at 03:23
  • 1
    Since you have the wget command to check, I suggest you check from localhost so you don't go through the ELB. – Law29 Oct 23 '18 at 14:34

1 Answers1

2

You have no ExpiresByType rule for the application/x-javascript Content-Type your .js file is being served as.

ceejayoz
  • 32,910
  • 7
  • 82
  • 106