Javascript Google缓存api-使用get参数缓存URL
我正在尝试缓存我的J2EE web应用程序页面。 我设法在没有任何参数的情况下缓存页面。但是对于在URL末尾附加GET参数的页面,我似乎不能这样做 有人能告诉我如何缓存带有get参数的网页吗 下面是我的代码:Javascript Google缓存api-使用get参数缓存URL,javascript,java,html,caching,Javascript,Java,Html,Caching,我正在尝试缓存我的J2EE web应用程序页面。 我设法在没有任何参数的情况下缓存页面。但是对于在URL末尾附加GET参数的页面,我似乎不能这样做 有人能告诉我如何缓存带有get参数的网页吗 下面是我的代码: const cacheName = 'sailors-cache'; const domainurl = '/The_Sailors_Application/Application/'; const cacheAssets = [ domainurl + 'images/log
const cacheName = 'sailors-cache';
const domainurl = '/The_Sailors_Application/Application/';
const cacheAssets = [
domainurl + 'images/logo.png',
domainurl + 'report-surveyor-generalinfo.html',
domainurl + 'report-surveyor-timelog.html',
domainurl + 'report-surveyor-acknowledgement.html',
domainurl + 'report-surveyor-barge.html',
domainurl + 'report-surveyor-bunker-condition.html',
domainurl + 'report-surveyor-bunker-condition2.html',
domainurl + 'report-surveyor-statement.html',
domainurl + 'report-surveyor-sealchecklist.html',
domainurl + 'report-surveyor-samplingreport.html',
domainurl + 'report-surveyor-vessel-measurement-report.html',
domainurl + 'report-surveyor-finalreport.html',
domainurl + 'report-surveyor-mass-flow-meter.html',
domainurl + 'report-surveyor-cargo.html',
domainurl + 'report-surveyor-checklist.html',
domainurl + 'report-surveyor-feedback.html',
domainurl + 'report-pictures.html',
domainurl + 'signature.html',
domainurl + 'assets/css/bootstrap.min.css',
domainurl + 'assets/css/normalize.css',
domainurl + 'assets/css/font-awesome.min.css',
domainurl + 'assets/css/themify-icons.css',
domainurl + 'assets/scss/style.css',
domainurl + 'assets/js/vendor/jquery-2.1.4.min.js',
domainurl + 'assets/js/plugins.js',
domainurl + 'assets/js/widgets.js'
];
// Call Install Event
self.addEventListener('install', e => {
console.log('Service Worker: Installed');
e.waitUntil(
caches
.open(cacheName)
.then(cache => {
console.log('Service Worker: Caching Files');
cache.addAll(cacheAssets);
})
.then(() => self.skipWaiting())
);
});
// Call Activate Event
self.addEventListener('activate', e => {
console.log('Service Worker: Activated');
// Remove unwanted caches
e.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cache => {
if (cache !== cacheName) {
console.log('Service Worker: Clearing Old Cache');
return caches.delete(cache);
}
})
);
})
);
});
// Call Fetch Event
self.addEventListener('fetch', e => {
console.log('Service Worker: Fetching');
e.respondWith(fetch(e.request).catch(() => caches.match(e.request)));
});
我要缓存的URL网页示例如下:
domainurl+“report surveyor generalinfo.html?referenceNumber=YF-1223-19”
谢谢。请粘贴您的代码,说明如何将URL添加到缓存,预期的URL是什么,实际的URL是什么URL@MuhammedImranHussain您好,我在您的代码上下文中编辑,您的动态/参数URL未缓存。您需要在获取时匹配url,如果不匹配,则将其放入缓存,然后返回,以便下次它将从缓存中提供服务。您可以在“网络响应”下找到详细信息title@MuhammedImranHussain对不起,我不太明白。您能再解释一下吗?您的代码缓存了report-surveyor-generalinfo.html,但没有report-surveyor generalinfo.html?referenceNumber=YF-1223-19。这里我假设referenceNumber是可变的。因此,您可以在用户交互时缓存此URL,例如在单击链接时,或者在网络响应时实现缓存。本文档中提到的用户交互和网络缓存响应示例请粘贴您的代码,说明如何将URL添加到缓存中,预期的URL是什么,实际的URL是什么URL@MuhammedImranHussain您好,我在您的代码上下文中编辑,您的动态/参数URL未缓存。您需要在获取时匹配url,如果不匹配,则将其放入缓存,然后返回,以便下次它将从缓存中提供服务。您可以在“网络响应”下找到详细信息title@MuhammedImranHussain对不起,我不太明白。您能再解释一下吗?您的代码缓存了report-surveyor-generalinfo.html,但没有report-surveyor generalinfo.html?referenceNumber=YF-1223-19。这里我假设referenceNumber是可变的。因此,您可以在用户交互时缓存此URL,例如在单击链接时,或者在网络响应时实现缓存。本文档中提到的用户交互和网络缓存响应示例