Skip to content

Commit

Permalink
ServiceWorker修复
Browse files Browse the repository at this point in the history
  • Loading branch information
2980077544 committed Dec 2, 2023
1 parent ff92493 commit dc67113
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
36 changes: 26 additions & 10 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,40 @@ <h2>友情链接</h2>
</footer>

<!--[if !IE]><script>fixScale(document);</script><![endif]-->
<script type="text/javascript">
{% if page.disableToc == nil %}
$(document).ready(function() {
$('#toc').toc();
});
{% endif %}
</script>

<script src="https://unpkg.zhimg.com/mdui@1.0.2/dist/js/mdui.min.js"></script>
<script type="text/javascript">
if(navigator.serviceWorker){
navigator.serviceWorker
.register('/sw.js')
.then((registration) => {console.log('Service Worker Registered. ', registration)})
.catch((error) => {console.log('ServiceWorker registration failed: ', error)})
navigator.serviceWorker.addEventListener('controllerchange', () => {
mdui.dialog({
title: '新版页面已经就绪',
content: '当前加载的是页面缓存,新版本页面已就绪,是否加载?',
buttons: [
{
text: '否'
},
{
text: '是',
onClick: function(inst){
window.location.reload();
}
}
]
});

})
}
</script>
<script src="https://unpkg.zhimg.com/mdui@1.0.2/dist/js/mdui.min.js"></script>

<script type="text/javascript">
{% if page.disableToc == nil %}
$(document).ready(function() {
$('#toc').toc();
});
{% endif %}
</script>
</body>

</html>
8 changes: 4 additions & 4 deletions sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
* Register service worker.
* ========================================================== */

const PRECACHE = 'precache-v1';
const PRECACHE = 'precache-v2';
const RUNTIME = 'runtime';
const HOSTNAME_WHITELIST = [
self.location.hostname,
"huangxuan.me",
"yanshuo.io",
"cdnjs.cloudflare.com"
"cdnjs.cloudflare.com",
"unpkg.com",
"unpkg.zhimg com",
]


Expand Down

0 comments on commit dc67113

Please sign in to comment.