AxaFrance / oidc-client

Light, Secure, Pure Javascript OIDC (Open ID Connect) Client. We provide also a REACT wrapper (compatible NextJS, etc.).
MIT License
571 stars 152 forks source link

Clear OidcServiceWorker cache every build #1310

Closed ozanmanav closed 4 months ago

ozanmanav commented 4 months ago

Issue and Steps to Reproduce

Since we have IIS Load balancer in our environment, the js files in dist/build need to be renewed every time there is a build. Since the file name remains the same, it remains cached. Does anyone have a solution suggestion for this?

Versions

7.19.0

Screenshots

image

Expected

A -postfix can be added to the OidcServiceWorker and OidcTrustedDomain files in every build. Or something can be done to reset caching.

Actual

Currently, the file remains cached because it has not changed.

guillaume-chervet commented 4 months ago

hi @ozanmanav ,

Thank you for your issue. I think I can try to add natively a query string when calling service worker file.

Like : ServiceWorker.js?v=4.5.3 What do you think about it? I never encourter the problem before, i do not know why.

ozanmanav commented 4 months ago

hi @ozanmanav ,

Thank you for your issue. I think I can try to add natively a query string when calling service worker file.

Like : ServiceWorker.js?v=4.5.3 What do you think about it? I never encourter the problem before, i do not know why.

Thanks for answer. Yeah maybe we can try add this version to there automatically. Not important version number just change file name maybe for every build, so we should able to set this from some where

ozanmanav commented 4 months ago

@guillaume-chervet For now, I did a workaround like this: I wrote the commit hash of the latest version of the application to localstorage and added something like clearing the serviceworker cache if the application changes. But of course this does not apply to OidcTrustedDomains.js.

image

image

guillaume-chervet commented 4 months ago

hi @ozanmanav ,

does v7.19.1-alpha.1372 version solve your problem? I have added a query string with the version of the library.

ozanmanav commented 4 months ago

hi @ozanmanav ,

does v7.19.1-alpha.1372 version solve your problem? I have added a query string with the version of the library.

Hey Thanks, Since we will not make any changes to this file without changing the library, this will be the solution. What can we do for OidcTrustedDomains.js? I think we need to do library independent versioning for it because it can change independently.

pgangwani commented 4 months ago

@ozanmanav @guillaume-chervet : I am using nginx and wrote Cache-Control: no-cache,must-revalidate for service worker. Isnt that should be doc change too?

ozanmanav commented 4 months ago

@ozanmanav @guillaume-chervet : I am using nginx and wrote Cache-Control: no-cache,must-revalidate for service worker. Isnt that should be doc change too?

Yeah good point thanks, For IIS, i think we can use disable caching for sw and trusted domains js like this: https://stackoverflow.com/a/15229507/5562701

@guillaume-chervet It looks like you don't need to take any further action for now, I'm closing this issue.