React-registerServiceWorker的作用

// In production, we register a service worker to serve assets from local cache.

// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on the “N+1” visit to a page, since previously
// cached resources are updated in the background.

// To learn more about the benefits of this model, read https://goo.gl/KwvDNy.
// This link also includes instructions on opting out of this behavior.
service worker是在后臺(tái)運(yùn)行的一個(gè)線程,可以用來處理離線緩存、消息推送、后臺(tái)自動(dòng)更新等任務(wù)。registerServiceWorker就是為react項(xiàng)目注冊(cè)了一個(gè)service worker,用來做資源的緩存,這樣你下次訪問時(shí),就可以更快的獲取資源。而且因?yàn)橘Y源被緩存,所以即使在離線的情況下也可以訪問應(yīng)用(此時(shí)使用的資源是之前緩存的資源)。注意,registerServiceWorker注冊(cè)的service worker 只在生產(chǎn)環(huán)境中生效(process.env.NODE_ENV === ‘production’)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容