modernweb-dev / web

Guides, tools and libraries for modern web development.
https://modern-web.dev
MIT License
2.2k stars 278 forks source link

[dev-server] stale-while-revalidate caching to improve performance #1157

Open bennypowers opened 3 years ago

bennypowers commented 3 years ago

We could use the Cache-Control: stale-while-revalidate header to improve performance of subsequent reloads of the dev-server

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#Extension_Cache-Control_directives

https://web.dev/stale-while-revalidate/

This should initially be implemented as a plugin. After gathering use cases and feedback, we can evaluate adding it by default.

LarsDenBakker commented 3 years ago

What about something like this:

import { cachePlugin } from '@web/dev-server-cache';

export default {
  plugins: [
    cachePlugin({
      rules: [
        { type: 'stale-while-revalidate', pattern: '**/*/node_modules/**/*' }
      ]
    }),
  ]
}