I'm checking my page in chrome's lighthouse and it says

"Serve static assets with an efficient cache policy"

and then a list of files, some of them have itok= , that's ok, I understand these should not be cached, but among the list are also other files, such as fonts, png files, webp files.

URL
Cache TTL
Transfer Size
…2021-11/film_standfilm_0.jpg.webp?itok=Ou17a4Ac
None
208 KiB
…fonts/Lato-Bold.woff2
None
181 KiB
…fonts/Lato-Regular.woff2
None
179 KiB
…fonts/Lato-Light.woff2
None
178 KiB
…css/css_frd-4….css
None
121 KiB

etc etc

I note that there are no jpg files, no ttf files and no woff files. so somewhere theres a setting caching these, but not the other filetypes ?

edit:
actually, I preload these local woff2 files in my template, because the font-your-face module wasn't doing it fast enough.

the question remains: how can I set the cache TTL on these files?

another thing, when I think about it, there are image files of picture styles that have itok tokens.
why is that - these files are static and should be cached too

Comments

jaypan’s picture

a list of files, some of them have itok= , that's ok, I understand these should not be cached

No, these files are cached. When the file is updated, the itok URL query parameter is changed, forcing the updated image to be downloaded and cached. Without this token, the browser wouldn't request the updated image, it's the change in value that forces the browser to request it, ignoring the cached file with the same name.

when I think about it, there are image files of picture styles that have itok tokens.
why is that - these files are static and should be cached too

Don't worry, they are cached. Check the network tab in a browser console, and you'll see that these files return 302 (found) responses, and the browser does not make a request to the server.

Contact me to contract me for D7 -> D10/11 migrations.

isalmanhaider’s picture

This can be achieved via .htaccess generically for all font files or even svgs
 

<filesMatch ".(woff2|ttf|otf|svg)$">
Header set Cache-Control "max-age=2628000, public"
</filesMatch>