Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring-MVC服务工人,用于渐进式webapps_Spring Mvc_Service Worker_Progressive Web Apps - Fatal编程技术网

Spring-MVC服务工人,用于渐进式webapps

Spring-MVC服务工人,用于渐进式webapps,spring-mvc,service-worker,progressive-web-apps,Spring Mvc,Service Worker,Progressive Web Apps,我有一个这样结构的应用程序: - webapp - - resources - - - js - - - - main.js - - WEB-INF - - - views - - - - index.jsp 我开始使用progressive webapp,我只想让index.jsp与其他视图一起工作。 index.jsp <head> <script defer src="resources/js/main.js"></script> <

我有一个这样结构的应用程序:

- webapp
- - resources
- - - js 
- - - - main.js
- - WEB-INF
- - - views
- - - - index.jsp 
我开始使用progressive webapp,我只想让index.jsp与其他视图一起工作。

index.jsp

<head>
    <script defer src="resources/js/main.js"></script>
</head>

不,不可能使用比SW.js所在位置更广的范围。换句话说:您可以使用scope选项来限制软件,但不能让它将软件的作用域向上扩展到目录结构

为了将“/”作为您的范围,您必须从“/SW.js”为SW.js提供服务


但是,您可以在html中添加一个特殊的头,为软件提供更大范围的访问权限。阅读更多关于它的信息

不,不可能使用比SW.js所在位置更广的范围。换句话说:您可以使用scope选项来限制软件,但不能让它将软件的作用域向上扩展到目录结构

为了将“/”作为您的范围,您必须从“/SW.js”为SW.js提供服务


但是,您可以在html中添加一个特殊的头,为软件提供更大范围的访问权限。阅读更多关于它的信息

我使用Spring的ResourceHandler解决了将服务工作者映射到应用程序根目录的问题

AppWebConfiguration.java

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/**")
        .addResourceLocations("/resources/");
    registry.addResourceHandler("/**")
        .addResourceLocations("/resources/js/sw.js");
}
通过以下内容,我可以使用以下脚本访问应用程序根目录下的sw.js:

main.js

navigator.serviceWorker&&navigator.serviceWorker.register('./sw.js')。然后(函数(注册){
log('很好,注册范围:',registration.scope);
}).catch(函数(错误){
console.log('服务工作者注册失败,错误:',错误);
警报(错误);

});我使用Spring的ResourceHandler解决了将服务工作者映射到应用程序根目录的问题

AppWebConfiguration.java

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/**")
        .addResourceLocations("/resources/");
    registry.addResourceHandler("/**")
        .addResourceLocations("/resources/js/sw.js");
}
通过以下内容,我可以使用以下脚本访问应用程序根目录下的sw.js:

main.js

navigator.serviceWorker&&navigator.serviceWorker.register('./sw.js')。然后(函数(注册){
log('很好,注册范围:',registration.scope);
}).catch(函数(错误){
console.log('服务工作者注册失败,错误:',错误);
警报(错误);
});