Static images cache expiry stuck at 1 month

286 visningar
Hoppa till det första olästa meddelandet

Ungov

oläst,
21 feb. 2022 18:40:572022-02-21
till mod-pagespeed-discuss
Pagespeed is caching most of my images and rewriting to webp. However, I have an images folder with a few jpg files that are not being cached and compressed to webp. When looking at the header of the image I see cache expiry is set to 1 month even if I set it to 1 year everywhere

headers.png

my .htaccess:
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/jpg "access plus 1 year"

nginx config:
        ExpiresByType image/jpg "access plus 1 year"
        ExpiresByType image/jpeg "access plus 1 year"

apache settings:
365days expiry for static files cache

Cloudflare config:
Caching Level: standard
Browser Cache TTL: respect existing headers

I also tried to temporarily disable Cloudflare, or create a page rule to force cache to "cache everything" with 1yr TTL, but it didn't change anything

Longinos

oläst,
21 feb. 2022 21:06:412022-02-21
till mod-pagespeed-discuss
Hi
These directives don´t work in nginx:
nginx config:
        ExpiresByType image/jpg "access plus 1 year"
        ExpiresByType image/jpeg "access plus 1 year"
and throw a error.
Is a mistake writing here?

Is this image folder under  /var/www/vhosts/******.com/public_html/?
How are loaded?
If these images are loaded by a javascript code then they are not rewrited, for example in a carousel.
If are loaded in a css file then some filter for images must be enabled
https://www.modpagespeed.com/doc/filter-css-rewrite

Ungov

oläst,
21 feb. 2022 21:38:072022-02-21
till mod-pagespeed-discuss
Hello,

The folder is in  /var/www/vhosts/******.com/public_html/images/homepage/
It's strange because images stored in another folder is working with correct cache expiration date  /var/www/vhosts/******.com/public_html/artworks/

The images are loaded normally in HTML
imggg.png

Longinos

oläst,
22 feb. 2022 04:47:362022-02-22
till mod-pagespeed-discuss
Hi
Sound like a server config issue cause pagespeed don´t set headers for this amount of time.
It put 1 year for optimized resources or leave the "original" headers otherwise.
Maybe is an .htacces file in this folder?
And the strnage thing is that are not rewrited by pagespeed.
You have
ModPagespeedLoadFromFile "https://www.******.com/" \
"/var/www/vhosts/******.com/public_html/"
so files under /var/www/vhosts/******.com/public_html/ are loaded from disk by pagespeed.
The LoadFrom File has a " characteristic ":

The files are loaded from disk so no http header are set, then pagespeed set a cache-control with the default 300 (5min)
The rest of headers are set not to the original resource but to the pagespeed rewrited one when is served by the web server.
The original cache-control header tell pagespeed how much time the optimized/rewrited resource hold in their cache, so if no original cache-control are set
and the defaul 5min is used, the resource need to be optimized every 5 min.
For solve ths there are 1 directive:
ModPagespeedLoadFromFileCacheTtlMs implicit_cache_ttl_in_milliseconds

Longinos

oläst,
22 feb. 2022 05:14:022022-02-22
till mod-pagespeed-discuss
Hi again
Can you try to use absolute url for these images.
I see in the image you posted:
<img src="/images/...."
change it to

Ungov

oläst,
23 feb. 2022 02:20:382022-02-23
till mod-pagespeed-discuss
Hello,

There is no .htaccess in /images/ folder
I tried adding ModPagespeedLoadFromFileCacheTtlMs 7776000000 (90 days) but it didn't change anything

Maybe the problem is not related to pagespeed. When I open the image file in my browser and record using chrome dev tools (network tab) the headers of the image also has 1 month expiry instead of 1 year

Longinos

oläst,
23 feb. 2022 04:52:002022-02-23
till mod-pagespeed-discuss
No, these directive can´t set the cache-control header, so you can´t view it.
As far as loading a file from disk there is no cache-control header so pagespeed stores the optimized resource in their cache forthe default,  5min,
pass this time, resource need to be optimized again.
This directive tell pagespeed to store the optimized resource in the pagespeed cache the amount of time you set.

Have you any ExpiresDefault config in the apache server?
How these files are loaded?
Maybe these DOM node is created by javascript?
From where are you loading the image? I will say, are you fechting the image from the nginx server or directly from the apache server?

Maybe is there a Directory config for this folder?
Can you try the debug parameter?
this put debug messases as html comments in the html code.
then in the html code find the image and see what the message is

Ungov

oläst,
25 feb. 2022 02:31:102022-02-25
till mod-pagespeed-discuss
When adding ?PageSpeedFilters=+debug
to the URL, i realized the images doesn't appear on the homepage.
then I looked at the PHP code and found this:

if (empty($_SERVER['QUERY_STRING'])) {
echo "<img src='...'>";
}

I assume pagespeed is adding a query string to the URL when scraping the site, so it didn't find the images

I edited the PHP code, and now pagespeed is picking up the images, converting them to webp, with correct headers (1year)

Thanks for your help, even if the problem was my code and not pagespeed!

Longinos

oläst,
25 feb. 2022 06:59:022022-02-25
till mod-pagespeed-discuss
Hi
Glad to hear you solved the issue.
Svara alla
Svara författaren
Vidarebefordra
0 nya meddelanden