首页 > 解决方案 > Google 缓存 api - 使用获取参数缓存 url

问题描述

我正在尝试缓存我的 J2EE Web 应用程序页面。我设法在没有任何参数的情况下缓存页面。但是对于在 URL 末尾附加 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',

谢谢你。

标签: javascriptjavahtmlcaching

解决方案


推荐阅读