LS, Via an index.html a new user can request for an access token. This token is sent to his/her email. The token must then be pasted in the token field to get access to the form. When the token is verified the form is shown. To prevent access to the source of the form before the correct token is inserted I want the cache to occur after the token is verified. I used the standard minimal registration, installing and activation of the service worker.

if (exists_token($_COOKIE['session_token'], 'sessions')){

How can I delay the caching until after the token is verified, when the form.html is rendered?

1 Answers

pate On

I suppose you have to write some custom logic in the Service Worker script. You can communicate with the SW from the page's JavaScript by using window.postMessage. Using that, you'll be able to not cache this or that by default and then, when your conditions are met, let the SW know caching can happen via postMessage.

However, I'm not sure your approach is wise. What happens in a future time if the token expires and the page is SW cache? You would need to write custom cache-eviction code to handle that.

I don't know your application logic but maybe you could always render the form and hide it from JS or using PHP/CSS based on token verification status or smth.