编辑 16/02/2021
项目架构(docker/nginx)
- dockercompose.yml
- app
- core
- app1 (many Django apps with similar archtiecture)
- static
- app1
- js
- script.js
- static
- css
- images
- js
- jquery.formset.js
- manifest.json
- templates
- layout
- base.html
...
- home.html
- offline.html
...
- serviceworker.js
- Dockerfile
- nginx
manifest.json
{
"name": "Intense TBM",
"short_name": "itbm",
"start_url": "/",
"display": "standalone",
"background_color": "#FFF",
"theme_color": "#493174",
"description": "Randomization app rescue for Intnse TBM trial ANRS 12398",
"dir": "ltr",
"lang": "en-US",
"orientation": "portrait-primary",
"icons": [
{
"src": "/static/images/intensetbm.png",
"type": "image/png",
"sizes": "160x160"
},
{
"src": "/static/images/intensetbm.png",
"type": "image/png",
"sizes": "160x160"
}
]
}
serviceworker.js
const VERSION = 'V1.0';
var staticCacheName = "intensetbm-pwa-v" + new Date().getTime();
var filesToCache = [
'/offline/',
'/static/css/styles.css'
];
self.addEventListener("install", event => {
this.skipWaiting();
event.waitUntil(
caches.open(staticCacheName)
.then(cache => {
return cache.addAll(filesToCache);
})
)
});
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames
.filter(cacheName => (cacheName.startsWith("intensetbm-pwa-")))
.filter(cacheName => (cacheName !== staticCacheName))
.map(cacheName => caches.delete(cacheName))
);
})
);
});
self.addEventListener("fetch", event => {
event.respondWith(
caches.match(event.request)
.then(response => {
return response || fetch(event.request);
})
.catch(() => {
return caches.match('/offline/');
})
)
});
编辑 11/02/2021 19:00
这似乎是由于包含在我的 base.html 中
{% include 'layouts/_nav.html' %}
{% include 'layouts/_footer.html' %}
我尝试将 Service Worker 添加到我的应用中。 但得到一个错误 Uncaught SyntaxError: Unexpected token '<'
使用调试工具,第一行 是每个文件的下划线和错误信息 我找不到任何解释...
希望有人能帮忙