Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ETags don't reflect modified content #46

Open
phillanier opened this issue Jan 23, 2019 · 1 comment
Open

ETags don't reflect modified content #46

phillanier opened this issue Jan 23, 2019 · 1 comment

Comments

@phillanier
Copy link

The interception appears to happen after ETag header has already been set for the response. Consequently, the ETag doesn't reflect the changed output, which can cause browser caching issues--even if the content is wildly different from one page load to the next, the server is telling the browser, "Nah, nothing changed since the last time you loaded this resource."

It's pretty simple (even if a little inefficient) to regenerate the ETag with another library (e.g., https://www.npmjs.com/package/etag) right before calling send(). But the whole ETag thing a hazard that most users are unlikely to recognize. Would be great to have a built-in option. Or at least a warning in the docs/examples

@Soviut
Copy link

Soviut commented Aug 11, 2020

We got hit by an ETag issue where every other request would fail to intercept. This was made even more difficult to diagnose because of the Disable Cache checkbox being checked in Chrome DevTools; The problem would go away when DevTools was open.

The issue we were having was that the interceptor would encounter an empty body because of the 304 Not Modified statusCode.

Our solution was to check the status code in the isInterceptable method.

    isInterceptable() {
      // Don't intercept cached responses (etag)
      return res.statusCode !== 304
    },

Alternatively, you can check the body in the intercept method.

    intercept(body, send) {
      if (!body) {
        send(body)
      } else {
        const stuff = JSON.parse(body)

        // do something...
        
        send(JSON.stringify(stuff))
      }
    },

Finally, if you don't want to write any of these checks and want to disable the server cache entirely via a config.

app.set('etag', false)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants