←back to thread

260 points gherkinnn | 1 comments | | HN request time: 0s | source
Show context
mh-cx ◴[] No.42164537[source]
I wonder why the article doesn't mention utilizing the browser cache for your static CSS and JS assets instead of introducing a service worker as first measure.

Few years ago I built a shopping site MPA this way and the page transitions were almost not noticable.

replies(7): >>42164573 #>>42164584 #>>42164743 #>>42168597 #>>42169927 #>>42170948 #>>42173755 #
jdsleppy ◴[] No.42164573[source]
Same (but not a shopping site). Bundle the JS and CSS into one file each and cache it forever (hash in the filename to bust the cache). Then with each page transition there's exactly one HTTP request to fetch a small amount of HTML and it's done. So fast and simple.
replies(3): >>42164678 #>>42166335 #>>42166710 #
1. mh-cx ◴[] No.42164678[source]
Exactly this. In our case we went so far to cache all static assets. Putting them into a directory with a hash in the name made them still easy to bust.

  # Cache static files
  location ~* \.(ico|css|js|gif|jpe?g|png|svg|woff|woff2)$ {
    expires 365d;
    add_header Pragma public;
    add_header Cache-Control "public";
    proxy_pass http://127.0.0.1:9000;
  }