DEV Community

Discussion on: SPAs: Have Your Cache And Eat It Too

Collapse
 
avxkim profile image
Alexander Kim

Thanks for the article, i missed these headers in my nginx config, in case someone wonders, on where to put them, here's an example in http block:

location / {
    root /path/to/your/built/files;
    try_files $uri $uri/ /index.html;
    add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate';
    expires 0;
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
jamesthomson profile image
James Thomson

Happy the article helped you. The only thing I'd note here is if you're using the no-store flag then no-cache, must-revalidate, proxy-revalidate is redundant as no-store will tell the browser to flat out never cache the file.

By contrast, "no-store" is much simpler. It simply disallows the browser and all intermediate caches from storing any version of the returned response—for example, one containing private personal or banking data. Every time the user requests this asset, a request is sent to the server and a full response is downloaded.

Source: developers.google.com/web/fundamen...

Collapse
 
sherlock1982 profile image
Nikolai Orekhov • Edited

I don't really get why to use "no-store" even. You can use "no-cache" and it will have forced revalidation on each request returning 304 most of the time if your index.html was not changed.
It also applies to any static files that doesn't have a "hashed" names for various reasons.

Thread Thread
 
chipit24 profile image
Robert Komaromi • Edited

I agree, no need to use no-store here as long as your server implements validation via etag or last-modified. Dev.to, for example, sets the following headers:

cache-control: public, no-cache
etag: W/"495a374b731c7d2a6d8758814988907f"
Enter fullscreen mode Exit fullscreen mode