Website is hosted on Firebase.
But the issue is, whenever we go to the website, let's say www.website.com
we need to refresh it at least twice in order to load the website.
Not sure what possibly could be the issue
Using Firebase Hosting to host our website, we have a custom URL where it's being re-routed to. (*1
)
npm run build
to create production build
deploying via firebase deploy
User tries to open the page in the 1st try it loads nothing but can see the following error:
Uncaught SyntaxError: Unexpected token < firebase-app.js:1
In the 2nd try the page loads correctly.
As listed by Frank in the comments it's not an issue from Firebase then is it something from React (Create-React-App)?
*1
- Have tried both routes, custom route and route provided by Firebase hosting, and the issue happens in both.
If you know a change has been made (such as when we update the address on your website), you will need to refresh the web page in order to see the updated information – refreshing the page tells the browser to go back to the server and see if there is anything new.
setTimeout(function(){ window. location. reload(); }, 5000); This example sets 5 seconds to reload the page, you can set the time as per your needs.
AJAX is a technique for creating fast and dynamic web pages. AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.
If you're using create-react-app
, the problem is that there is a service worker that is likely caching the page for offline use. Service workers were enabled by default until CRA v2.0 (which is different versioning from react-scripts
). It can take a few reloads to get the fresh content because the service worker, which is persisting in the browser between reloads, is what is actually hitting your hosting service to look for new content. By default, it always loads instantly from cache, until it has a chance to hit the server to check for new content. By default, the browser's console will output once you've been on a stale web page for a few seconds with New content available! Please reload.
. The next refresh pulls the new content into the browser's cache.
If you just want to turn it off for development in Chrome, once you have your website loaded, you can go into the dev tools>Application>Service Workers
. Once you're there, there are several checkboxes for the service worker for that website. You can check Update on reload
and Bypass for network
.
However, if you want to permanently disable service workers, you have to unregister them first from all existing registered users. If you just remove the file called service-worker.js
, it will not unregister it for users who have already accessed your site, which is problematic. In order to remove the service worker from clients who have already accessed your site, you'll have to unregister it. In your index.js
file at the root of the src
folder, you need to change this
import registerServiceWorker from './registerServiceWorker';
registerServiceWorker();
to
import { unregister } from './registerServiceWorker';
unregister();
What you are doing is preventing it from further registering service workers (by removing the registerServiceWorker
function) and unregistering any existing service workers by calling the unregister
function. The service worker might be on any number of browsers, so it's best to unregister, instead of only removing the registerServiceWorker
function.
You can read more about service workers on the create-react-app
docs site.
Here's a link to the github issue in which the authors of CRA explain how to disable the service worker.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With