Context, expires and 404s

#1
I'm trying to set expires headers for JS and CSS files and I'm following the guide here: https://openlitespeed.org/kb/how-to-set-up-custom-headers/

This is how I have set up the context:
URI: exp:^.*\.(css|js)$ (I want to find any files with a .css or .js extension, some of the files may have a parameter on the end like ?v=123456 (which is the last modified time stamp)
Location: $DOC_ROOT/$0
Accessible: Yes
Enable expires: Yes
Expires by type: application/javascript=A86400, text/css=A86400
Header operations:
unset Cache-control
set Cache-control public, max-age=86400

All other things are blank/defaults

What happens:

The expires headers and settings work as they should but all matched files return a 404, such as:
https://xxx.co.uk/js/jquery-3.5.0.min.js
https://xxx.co.uk/slick/slick.min.js?v=1587560009

(replaced domain name with xxx.co.uk)

Removing the context and the files are all found again.

So the regular expression seems to be working, the expires/headers are added but I think the location isn't quite right so it's not finding the file maybe?

Any help would be greatly received!

TIA
 

gilles

Active Member
#3
Personally, I think expire headers are better set at the server level, under General > Expire Settings > Expires By Type.
One should not have to set a separate context for them.

This is what I have set:
image/*=A31557600, text/css=A31557600, application/x-javascript=A31557600, application/javascript=A31557600, text/javascript=A31557600, font/*=A31557600, application/x-font-ttf=A31557600, application/x-font-woff=A31557600, application/font-woff=A31557600, application/font-woff2=A31557600
86400 seconds is a week, which is a bit short for browser caching.
 
#4
We have four virtual hosts all running the same platform while one of them is our staging platform - we wanted to try this out on the staging platform first before rolling out to the others.

The issue was the $DOC_ROOT just didn't work - the 404 errors returned were because the the path was incorrect.
 
Top