大家好,我是这项技术的新手,我想为我的代码寻求帮助。我想要做的是缓存资产文件并从服务工作者返回。
这是用于注册服务工作者的代码
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/serviceworker.js')
.then(function(reg) {
// registration worked
console.log('Registration succeeded. Scope is ' + reg.scope);
}).catch(function(error) {
// registration failed
console.log('Registration failed with ' + error);
});
}
这是服务工作者内部的代码
importScripts('/cache-poli.js');
var CACHE_VERSION = 'app-v2';
var CACHE_FILES = [
'/',
'/js/plugins/bootstrap/js/bootstrap.min.js',
'/js/plugins/bootstrap-select/bootstrap-select.min.js',
'/js/plugins/prettyphoto/js/jquery.prettyPhoto.js',
'/js/plugins/jquery.sticky.min.js',
'/js/plugins/jquery.easing.min.js',
'/js/plugins/animate/js/animate.js',
'/js/jquery.fancybox.js',
'/js/plugins/jquery/jquery-ui-1.11.1.min.js',
'/js/jquery.scrollbar.min.js',
'/js/plugins/owlcarousel2/owl.carousel.min.js',
'/js/plugins/elevateZoom/jquery.elevateZoom-3.0.8.min.js',
'/js/theme.js',
'/js/cmsfuncs.js',
'/js/theme-config.js',
'/js/jquery.mCustomScrollbar.concat.min.js',
'/js/plugins/jquery/jquery-2.1.4.min.js',
'/js/jquery.cookie.js',
'/js/plugins/bootstrap/css/bootstrap.min.css',
'/fonts/fontawesome/css/font-awesome.min.css',
'/fonts/webfont/css/simple-line-icons.css',
'/fonts/elegantfont/css/elegantfont.css',
'/js/plugins/bootstrap-select/bootstrap-select.min.css',
'/js/plugins/owlcarousel2/assets/owl.carousel.min.css',
'/js/plugins/prettyphoto/css/prettyPhoto.css',
'/js/plugins/animate/css/animate.css',
'/s/plugins/accordion/css/magicaccordion.css',
'/css/jquery.scrollbar.css',
'/css/megamenu.css',
'/css/theme.css',
'/css/slider/slide.css',
'/css/jquery.mCustomScrollbar.css',
'/css/responsive.css',
'/css/theme.css'
];
self.addEventListener('install', function (event) {
event.waitUntil(
caches.open(CACHE_VERSION)
.then(function (cache) {
console.log('Opened cache');
return cache.addAll(CACHE_FILES);
})
);
});
self.addEventListener('activate', function (event) {
event.waitUntil(
caches.keys().then(function(keys){
return Promise.all(keys.map(function(key, i){
if(key !== CACHE_VERSION){
return caches.delete(keys[i]);
}
}))
})
)
});
self.addEventListener('fetch', function (event) {
event.respondWith(
caches.open(CACHE_VERSION).then(function(cache){
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
})
)
});
我正在使用Google Chrome开发工具查看安装过程,所有内容都应该缓存,服务工作者没有显示任何错误,但是当我再次尝试访问该网站时,它会给我一个错误。
无法访问此网站 domain.com上的网页可能暂时关闭,或者可能已永久移动到新的网址。
答案 0 :(得分:1)
我也有同样的错误。
实际上,问题是不言自明的。浏览器告诉您的是,您尝试访问的路径无法访问。
在您的代码中,您似乎已缓存根Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Private Const VK_SNAPSHOT As Byte = 44
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal _
lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal _
nCmdShow As Long) As Long
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function EmptyClipboard Lib "user32" () As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Private Const SW_SHOWMAXIMIZED = 3
Private Const VK_LCONTROL As Long = &HA2
Private Const VK_V = &H56
Private Const vk_Escape = 27
Private Const KEYEVENTF_KEYUP = &H2
Public Function ClearClipboard()
OpenClipboard (0&)
EmptyClipboard
CloseClipboard
End Function
Sub Screenshot()
OpenClipboard (0&)
EmptyClipboard
CloseClipboard
Dim IE As Object
Dim hwnd As Long, IECaption As String
Dim fdate As Date
'~~> Change Status and unmerge
Range("B11").Value = "Running"
ThisWorkbook.Sheets("SAT").Range("B18:D33").UnMerge
Application.WindowState = xlMinimized
'~~> Launch URL
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "URL LINK"
Sleep 5000
'~~> Get the caption of IE
IECaption = "Clinical Console © - Internet Explorer"
Sleep 3000
'~~> Get handle of IE
hwnd = FindWindow(vbNullString, IECaption)
If hwnd = 0 Then
MsgBox "IE Window Not found!"
Exit Sub
Else
'~~> Maximize IE
ShowWindow hwnd, SW_SHOWMAXIMIZED
End If
DoEvents
'~~> Snapshot of window & Paste into Sheet location
Sleep 5000
keybd_event vk_Escape, 0, 0, 0
Sleep 4000
Call GetWindow
Application.SendKeys "(%{1068})"
Sleep 2000
Application.SendKeys ("%{F4}")
ThisWorkbook.Sheets("SAT").Range("B18").Select
ActiveSheet.Paste Destination:=Worksheets("SAT").Range("B18")
Application.WindowState = xlMaximized
'~~> Tidy up and update status
Sheets("SAT").Range("B18:D33").Merge
Range("B11").Value = "Completed: Screen Captured"
'ActiveWorkbook.Save
End Sub
Sub CallScreenshot()
Call Screenshot
End Sub
Sub GetWindow()
Dim IE As Object
Dim hwnd As Long, IECaption As String
Dim fdate As Date
'~~> Get the caption of IE
IECaption = "Clinical Console © Login Error - Internet Explorer"
'~~> Get handle of IE
hwnd = FindWindow(vbNullString, IECaption)
If hwnd = 0 Then
MsgBox "IE Window Not found!"
Exit Sub
Else
'~~> Maximize IE
ShowWindow hwnd, SW_SHOWMAXIMIZED
End If
End Sub
。我假设您在尝试访问'/'
等其他路径时遇到此问题
因为您没有缓存这些,所以您收到此错误。
所以在你的数组中如果你还添加:
'/somepath'
不会发生错误。
我使用完全相同的方法,错误消失了。