Static images cache expiry stuck at 1 month

93 views
Skip to first unread message

Ungov

unread,
Feb 21, 2022, 6:40:57 PMFeb 21
to 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

unread,
Feb 21, 2022, 9:06:41 PMFeb 21
to 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

unread,
Feb 21, 2022, 9:38:07 PMFeb 21
to 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

unread,
Feb 22, 2022, 4:47:36 AMFeb 22
to 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

unread,
Feb 22, 2022, 5:14:02 AMFeb 22
to 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

unread,
Feb 23, 2022, 2:20:38 AMFeb 23
to 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

unread,
Feb 23, 2022, 4:52:00 AMFeb 23
to 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

unread,
Feb 25, 2022, 2:31:10 AMFeb 25
to 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

unread,
Feb 25, 2022, 6:59:02 AMFeb 25
to mod-pagespeed-discuss
Hi
Glad to hear you solved the issue.
Reply all
Reply to author
Forward
0 new messages