2

プログレッシブWebアプリケーションで静的ファイルとリモートファイルをキャッシュしようとしています。サービスワーカー:リモートファイルがキャッシュされない

静的ファイルはキャッシュされますが、リモートファイルはキャッシュされません。

browser caching of static & remote files

ここでは、コードです:事前に

self.addEventListener('install', e => { 
    e.waitUntil(
     caches.open('offline') 
     .then(cache => cache.addAll([ 
      '/', 
      'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css', 
      'https://code.jquery.com/jquery-3.2.1.js', 
      'scripts/firebase.js', 
      'scripts/localForage.js', 
      'old-index.html', 
      'scripts/main.js', 
     ])) 
    ); 
}); 

おかげ

ここで更新されたコード

var filesToCache = [ 
    '.', 
    "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker.css", 
    'https://code.jquery.com/jquery-3.2.1.js', 
    'scripts/firebase.js', 
    'scripts/localForage.js', 
    'cce.html', 
    'scripts/main.js', 
    'scripts/secondary.js', 
    'https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css' 
]; 

var staticCacheName = 'pages-cache-v1'; 

self.addEventListener('install', function(event) { 
    console.log('Attempting to install service worker and cache static assets'); 
    event.waitUntil(
    caches.open(staticCacheName) 
    .then(function(cache) { 
     return cache.addAll(filesToCache); 
    }) 
); 
}); 

答えて

0

私はあなたが同じフォーマットを使用していない推測だがこのの。ここでは、このthreadからサンプルコードを示します:

self.addEventListener('install', function(e) { 
    e.waitUntil(
    caches.open('airhorner').then(function(cache) { 
     return cache.addAll([ 
     'https://paul.kinlan.me/' 
     ]); 
    }) 
); 
}); 
+0

私は、サンプルコードだけでなく、ドキュメント内の1つを試してみましたが、問題はまだ関係します。 – user3287355

+0

このコードが動作しない他の問題はありますか? – user3287355

関連する問題