saeho
saeho2mo ago

A way to render code only if JS code can't be run

I noticed (at least in development), that when the app refreshes due to code change, and if I press back button to go to a previous version of the app which is no longer valid, the app doesn't work (rightfully so, because the previous iteration of the dev app no longer exists). Interestingly, I noticed that the HTML code generated by previous version of the now non-existent app, stilll works. But this previous version of the app is static HTML, and JS does not work until I refresh the app. I'd like to know if it's possible to show a different code to ask the user to "refresh the page" if a user reaches this problem. Note: I have not tested this in production, so I do not know if this is a problem in production.
1 Reply
Deno AI Helper
Deno AI Helper2mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the information you've provided, it sounds like you're looking for a way to handle stale application states when using a live-reloading development environment. One common approach to handle this scenario in web applications (not specific to Deno) is to use a service worker that can detect when the version of the app has changed and prompt the user to refresh the page. Alternatively, you could include a version identifier in your app's assets and use JavaScript to check if the current version matches the expected one. If it doesn't, you can display a message to the user to refresh the page. Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of this advice and consider it as a general web development strategy rather than something specific to Deno. In production, depending on your deployment strategy, you might not encounter this issue if you have proper cache invalidation and versioning strategies in place. It's always a good idea to test your application in a production-like environment to ensure that such issues are addressed before your users encounter them.