Dha*_*osh 9 javascript node.js npm firebase reactjs
网站托管在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.
可能您的问题是某些资源已缓存。如果重新加载一次,浏览器将仅重新加载主URL。如果重新加载两次,其他资源将被刷新。因此,这可能是一些奇怪的行为。
有一些技巧,例如,如果您可以更改js文件的网址,请将其从http://yoursite/folder/file.js更改为http://yoursite/folder/file.js?_ = TIMESTAMP,其中TIMESTAMP是一个时间戳,例如从js上的new Date()。getTime()或php上的time()获得的(每种语言都有获取时间戳的方法)。该_参数将使缓存无效。如果可行,则可以使用更优雅的方法告诉浏览器根据需要处理缓存。