Google缓存API-使用get参数缓存网址

时间:2019-04-01 13:35:01

标签: javascript java html caching

我正在尝试缓存我的J2EE Web应用程序页面。 我设法缓存没有任何参数的页面。但是对于在URL末尾附加了GET参数的页面,我似乎没有这样做。

有人可以指导我如何使用get参数缓存网页吗?

下面是我的代码:

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'

谢谢。

0 个答案:

没有答案