-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Feature Request
Problem / Opportunity
Pagespeed Insights recommends improving cache lifetimes for our static assets to save an estimated 272 KiB and speed up repeat visits. Currently, many assets (images, SVGs, covers, etc.) have cache TTLs of only 1-3 hours, which is much shorter than it could be.
A long cache lifetime can make Open Library pages load faster for users, especially those accessing frequently-used resources such as covers and UI images.
Reference analysis: Pagespeed Insights result
Justification
Implementing proper caching headers for static assets can reduce transfer size, lower server overhead, and improve perceived speed for users.
Breakdown
Related files
- Static asset handlers (image, CSS, SVG, GIF uploads) ; not sure where the code for where this happens in the local environment is.
- in prod, static assets come from here:
openlibrary/docker/web_nginx.conf
Lines 155 to 177 in bec96c4
location ~ ^/(images/.*|favicon.ico|robots.txt)$ { rewrite ^(.*)$ /static/$1 last; } location ~ ^/(y_key_[0-9a-f]+.html|LiveSearchSiteAuth.xml)$ { root /olsystem/www; } location ~ ^/static/(docs|tour|sitemaps|jsondumps|images/shelfview|sampledump.txt.gz)(/.*)?$ { root /sitemaps; autoindex on; rewrite ^/static/(.*)$ /$1 break; } location /static { autoindex on; expires 1h; } location /static/build { expires max; } - Covers; see . It seems like this is trying to set it to 100 years with
openlibrary/openlibrary/coverstore/code.py
Lines 271 to 282 in f362492
if key == 'id': etag = f"{d.id}-{size.lower()}" if not web.modified(trim_microsecond(d.created), etag=etag): return web.notmodified() web.header('Cache-Control', 'public') # this image is not going to expire in next 100 years. web.expires(100 * 365 * 24 * 3600) else: web.header('Cache-Control', 'public') # Allow the client to cache the image for 10 mins to avoid further requests web.expires(10 * 60) web.expires, but it doesn't appear to be working.
May need to audit current asset serving and add Cache-Control headers or similar to extend cache lifetime for images and other static resources.