Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback with ExpiresDefault does not seem to include images #370

Closed
creopard opened this issue Apr 9, 2024 · 7 comments · Fixed by #371
Closed

Fallback with ExpiresDefault does not seem to include images #370

creopard opened this issue Apr 9, 2024 · 7 comments · Fixed by #371

Comments

@creopard
Copy link
Contributor

creopard commented Apr 9, 2024

Expected result:

Image files like PNG, GIF, JPG, WEBP, etc. use the default fallback time thats defined with "ExpiresDefault", i.e. 1 year.

Actual result:

Google Lighthouse complaines about "Serve static assets with an efficient cache policy" as the images will only have a cache TTL of 7 days (=604800 seconds).

Tested Browsers: Chrome 123, Firefox 124
Webserver: I do not run an Apache webserver, but a "Litespeed" webserver (Apache compatible alternative).

Issue:

With the current setting of

ExpiresDefault "access plus 1 year"

The HTTP answer header of an image will look like this:

HTTP/2 200 
cache-control: public, max-age=604800
content-type: image/gif
server: LiteSpeed

Fix:

Uncommenting

# ExpiresByType image/* "access plus 1 year" # default

will set the cache TTL correctly to 1 year (= 31536000 seconds).

So it seems that the currently commented section of "Generic:" does not use the fallback time of "ExpiresDefault" as initially anticipated?

@LeoColomb
Copy link
Member

Thanks for opening this issue @creopard.
That being said, the behavior you are facing is weird.
Indeed, the unit test framework used to validate the configuration explicitly checks Cache-Control value:

https://github.com/h5bp/server-configs-test/blob/a3dee296da841834aa2d130c1f887751553a5e58/lib/basic-file-access.json#L11

I'm not excluding the option that these tests are weak, but I'd appreciate more investigation on your side.
Are you sure LiteSpeed is following ExpiresDefault same as Nginx?

@creopard
Copy link
Contributor Author

creopard commented Apr 10, 2024

Are you sure LiteSpeed is following ExpiresDefault same as Nginx?
I've looked up the default config, although I can't access the one used by the webhoster. It seems the default comes from the main/global config file: https://openlitespeed.org/kb/openlitespeed-directive-working-in-progress/#expiresDefault

expiresDefault A604800
expiresByType image/*=A604800, text/css=A604800, and so on...

meaning that everything defaults to 1 week.
I was also wondering where that 1 week setting initially came from.

Assumption: If the value of expiresDefault will be overridden by the .htaccess with access plus 1 year, this seeting does not seem to affect the preset done in the above main config file expiresByType image/*=A604800 but only types that have no default setting yet.

Hence, (in my case) I need to explicitly set expiresByType image/* as well in the .htaccess file order to override the default from the main file.

It would be great if anybody else could also look up the expiry dates of images in a real world example.
Or is it just me? In the latter case, we can close this issue of course ;-)

@LeoColomb
Copy link
Member

Assumption: If the value of expiresDefault will be overridden by the .htaccess with access plus 1 year, this seeting does not seem to affect the preset done in the above main config file expiresByType image/*=A604800 but only types that have no default setting yet.

That sounds to be the good assumption 😊
But it is for the same assumption that I'd advocate to avoid uncommenting this section.
It's always easier to raise the granularity when needed than "fixing" the upper specific generics.
I hope it makes sense!

@creopard
Copy link
Contributor Author

Sure, I would just make people (who can't see the webhosters config, if they are on shared environments) aware that the entry
ExpiresDefault "access plus 1 year"
does not seem to be an automatic fallback scenario for every type that have not been mentioned in the .htaccess explicitly.

@LeoColomb
Copy link
Member

@creopard Sounds reasonable. Would you like to submit a PR to add this note?

@creopard
Copy link
Contributor Author

Added pull request: #371

@LeoColomb
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants