#SSR and document request caching

4 messages · Page 1 of 1 (latest)

soft mural
#

Not sure if this is Nuxt related (or if this is specific to me running the webapp on localhost?) but I'm running into a strange issue with document caching.

I have an SSR eCommerce app that stores a locale preference in a cookie. A user visits the URL, /cart and everything renders correctly on the server, they are shown content in their preferred locale.

Users can change locale on the client side and new data is fetched, so they might switch from e.g. GB to FR. All works fine without needing to refresh the document.

However when a user follows an external link—for example to the externally hosted checkout—and then hits back in the browser, no SSR is triggered because the browser serves up the cached document for /cart (i.e. the browser shows disk cache in the request size column) request with the previous—incorrect—locale.

Any ideas? Is this something I should be controlling with response headers? Thanks!

soft mural
#

Is this inadvisable?

/server/middleware/cache-control.ts

export default defineEventHandler((event) => {
  event.node.res.setHeader('Cache-Control', 'no-store');
});
glad matrix
#

so to cover this tiny edge you want to turn off whole caching and ruin user experience?

  • when client caches data you can't ask them to drop it because they never call you back
    what is the solution no-cache at all ... but this horrible!

other solutions?
try to drop cache in client side

this will ignore all caches and reload your whole page:

 window.location.reload(true)

i think it's feasible because you know where you are changing the locale,

if you want other pages to drop caches as well then you can't,
you can however add something to the end of your path to force browser to reload data -

/de for index
/car/de for cart
....

#

@soft mural