大家好,我是这项技术的新手,我想为我的代码寻求帮助。我想做的是缓存资产文件并从服务人员返回。
\n\n这是我用来注册服务工作者的代码
\n\nif ('serviceWorker' in navigator) {\nnavigator.serviceWorker.register('/serviceworker.js')\n.then(function(reg) {\n// registration worked\nconsole.log('Registration succeeded. Scope is ' + reg.scope);\n}).catch(function(error) {\n// registration failed\nconsole.log('Registration failed with ' + error);\n});\n}\nRun Code Online (Sandbox Code Playgroud)\n\n这是 Service Worker 内部的代码
\n\nimportScripts('/cache-poli.js');\n\nvar CACHE_VERSION = 'app-v2';\nvar CACHE_FILES = [\n'/',\n '/js/plugins/bootstrap/js/bootstrap.min.js',\n '/js/plugins/bootstrap-select/bootstrap-select.min.js',\n '/js/plugins/prettyphoto/js/jquery.prettyPhoto.js',\n '/js/plugins/jquery.sticky.min.js',\n '/js/plugins/jquery.easing.min.js',\n '/js/plugins/animate/js/animate.js',\n '/js/jquery.fancybox.js',\n '/js/plugins/jquery/jquery-ui-1.11.1.min.js',\n '/js/jquery.scrollbar.min.js',\n '/js/plugins/owlcarousel2/owl.carousel.min.js',\n '/js/plugins/elevateZoom/jquery.elevateZoom-3.0.8.min.js',\n '/js/theme.js',\n '/js/cmsfuncs.js',\n '/js/theme-config.js',\n '/js/jquery.mCustomScrollbar.concat.min.js',\n '/js/plugins/jquery/jquery-2.1.4.min.js',\n '/js/jquery.cookie.js',\n\n '/js/plugins/bootstrap/css/bootstrap.min.css',\n '/fonts/fontawesome/css/font-awesome.min.css',\n '/fonts/webfont/css/simple-line-icons.css',\n '/fonts/elegantfont/css/elegantfont.css',\n '/js/plugins/bootstrap-select/bootstrap-select.min.css',\n '/js/plugins/owlcarousel2/assets/owl.carousel.min.css',\n '/js/plugins/prettyphoto/css/prettyPhoto.css',\n '/js/plugins/animate/css/animate.css',\n '/s/plugins/accordion/css/magicaccordion.css',\n '/css/jquery.scrollbar.css',\n '/css/megamenu.css',\n '/css/theme.css',\n '/css/slider/slide.css',\n '/css/jquery.mCustomScrollbar.css',\n '/css/responsive.css',\n '/css/theme.css'\n];\n\nself.addEventListener('install', function (event) {\nevent.waitUntil(\n caches.open(CACHE_VERSION)\n .then(function (cache) {\n console.log('Opened …Run Code Online (Sandbox Code Playgroud)