I am converting my Django project to a progressive web app, and i am trying to precache my my files for them to be available offline. My problem is, I dont know how to locate my templates (e.g. homepage.html, index.html) to precache them using my service worker. I placed my service worker inside the static folder.
My current folder structure looks like this:
main/
-- migrations/
-- static/
---- js/
------ core/
------ plugins/
------ app.js
---- css/
---- img/
---- templates/
------ base.html
------ about.html
------ homepage.html
----*serviceWorker.js*
-- __init.py__
-- admin.py
-- apps.py
-- models.py
-- views.py
my_second_app/
-- migrations/
-- static/
---- js/
------ index.js
---- css/
---- img/
---- templates/
------ base.html
------ user.html
------ page.html
-- __init__.py
How can I map the HTML templates for my main app and my_second_app on my serviceWorker.js inside the static folder? Thanks in advance for anyone who could help. And let me know if I am doing it wrong :)
Anyway, I have successfully precached the static files. This is my code sample.
const precached = [
'/',
'/screener/',
'/accounts/login/',
'/accounts/signup/',
'/assets/js/now-ui-dashboard.js',
'/assets/js/core/bootstrap.min.js',
'/assets/js/core/jquery-ui.min.js',
'/assets/js/core/jquery.3.2.1.min.js',
'/assets/js/plugins/chart.bundle.min.js',
'/assets/css/accounts.css',
'/assets/css/bootstrap.min.css',
'/assets/css/now-ui-dashboard.css',
'/assets/css/user.css',
'/assets/fonts/nucleo-outline.ttf'
]
self.addEventListener('install', function (event) {
event.waitUntil(
caches.open(staticCacheName).then(cache => {
return cache.addAll(precached);
})
.then(() => {
return self.skipWaiting();
})
);
});