Search code examples
cachingnuxt.jsworkbox

Nuxt Efficient Cache


Serve static assets with an efficient cache policy. I get this if I audit my app. I added this code to nuxt.config but this would help.

render: {
  static: {
    maxAge: 2592000
  }
},

its by default caching static assets 1h in browser. Where can I change it. or How?


Solution

  • You should configure your headers for your static files with Firebase:

    https://firebase.google.com/docs/hosting/full-config#headers

    // in firebase.json
    "hosting": {
      // ...
    
      // Add the "headers" attribute within "hosting", override cache control
      "headers": [ {
        "source": "**/*.@(jpg|jpeg|gif|png)",
        "headers": [ {
          "key": "Cache-Control",
          "value": "max-age=2592000"
        } ]
      }
     ]
    }
    
    

    This should give you the desired cache control values, depending on what you want to set there.