mirror of
https://github.com/lnbits/lnbits.git
synced 2025-07-01 02:51:29 +02:00
remove CACHE_VERSION from service-worker.js (#2342)
use server_startup_time as the version (the same trick we use for static files)
This commit is contained in:
10
Makefile
10
Makefile
@ -86,7 +86,7 @@ bak:
|
|||||||
sass:
|
sass:
|
||||||
npm run sass
|
npm run sass
|
||||||
|
|
||||||
bundle_no_bump:
|
bundle:
|
||||||
npm install
|
npm install
|
||||||
npm run sass
|
npm run sass
|
||||||
npm run vendor_copy
|
npm run vendor_copy
|
||||||
@ -97,16 +97,10 @@ bundle_no_bump:
|
|||||||
npm run vendor_bundle_js
|
npm run vendor_bundle_js
|
||||||
npm run vendor_minify_js
|
npm run vendor_minify_js
|
||||||
|
|
||||||
bundle:
|
|
||||||
make bundle_no_bump
|
|
||||||
# increment serviceworker version
|
|
||||||
awk '/CACHE_VERSION =/ {sub(/[0-9]+$$/, $$NF+1)} 1' lnbits/static/js/service-worker.js > lnbits/static/js/service-worker.js.new
|
|
||||||
mv lnbits/static/js/service-worker.js.new lnbits/static/js/service-worker.js
|
|
||||||
|
|
||||||
checkbundle:
|
checkbundle:
|
||||||
cp lnbits/static/bundle.min.js lnbits/static/bundle.min.js.old
|
cp lnbits/static/bundle.min.js lnbits/static/bundle.min.js.old
|
||||||
cp lnbits/static/bundle.min.css lnbits/static/bundle.min.css.old
|
cp lnbits/static/bundle.min.css lnbits/static/bundle.min.css.old
|
||||||
make bundle_no_bump
|
make bundle
|
||||||
diff -q lnbits/static/bundle.min.js lnbits/static/bundle.min.js.old || exit 1
|
diff -q lnbits/static/bundle.min.js lnbits/static/bundle.min.js.old || exit 1
|
||||||
diff -q lnbits/static/bundle.min.css lnbits/static/bundle.min.css.old || exit 1
|
diff -q lnbits/static/bundle.min.css lnbits/static/bundle.min.css.old || exit 1
|
||||||
@echo "Bundle is OK"
|
@echo "Bundle is OK"
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
// update cache version every time there is a new deployment
|
// update cache version every time there is a new deployment
|
||||||
// so the service worker reinitializes the cache
|
// so the service worker reinitializes the cache
|
||||||
const CACHE_VERSION = 123
|
const CURRENT_CACHE = 'lnbits-{{ cache_version }}-'
|
||||||
const CURRENT_CACHE = `lnbits-${CACHE_VERSION}-`
|
|
||||||
|
|
||||||
const getApiKey = request => {
|
const getApiKey = request => {
|
||||||
let api_key = request.headers.get('X-Api-Key')
|
let api_key = request.headers.get('X-Api-Key')
|
||||||
@ -17,8 +16,7 @@ self.addEventListener('activate', evt =>
|
|||||||
caches.keys().then(cacheNames => {
|
caches.keys().then(cacheNames => {
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
cacheNames.map(cacheName => {
|
cacheNames.map(cacheName => {
|
||||||
const currentCacheVersion = cacheName.split('-').slice(-2, 2)
|
if (!cacheName.startsWith(CURRENT_CACHE)) {
|
||||||
if (currentCacheVersion !== CACHE_VERSION) {
|
|
||||||
return caches.delete(cacheName)
|
return caches.delete(cacheName)
|
||||||
}
|
}
|
||||||
})
|
})
|
@ -352,9 +352,16 @@ async def lnurlwallet(request: Request):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@generic_router.get("/service-worker.js", response_class=FileResponse)
|
@generic_router.get("/service-worker.js")
|
||||||
async def service_worker():
|
async def service_worker(request: Request):
|
||||||
return FileResponse(Path("lnbits", "static", "js", "service-worker.js"))
|
return template_renderer().TemplateResponse(
|
||||||
|
"service-worker.js",
|
||||||
|
{
|
||||||
|
"request": request,
|
||||||
|
"cache_version": settings.server_startup_time,
|
||||||
|
},
|
||||||
|
media_type="text/javascript",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@generic_router.get("/manifest/{usr}.webmanifest")
|
@generic_router.get("/manifest/{usr}.webmanifest")
|
||||||
|
Reference in New Issue
Block a user