简体   繁体   English

无法在appcache文件中使用正确的url

[英]Unable to use proper url's in appcache file

TL;DR- I think that something in struts/rest/spring-security are playing havock with my urls for both my manifest file, as well as the paths within the actual manifest file, but I cannot find any information on what that may be. TL; DR-我认为struts / rest / spring-security中的某些内容正在影响清单文件以及实际清单文件中的路径的URL,但是我找不到有关该内容的任何信息。

Now, the full description. 现在,完整描述。

I've been working recently to make a website that offers an offline option for certain page, but I've gotten stuck. 我最近一直在努力创建一个为某些页面提供脱机选项的网站,但我陷入了困境。 It seems that I am unable to use URLs in the way that I expect based off of the documentation and many tutorials I have looked at. 似乎无法根据我所看的文档和许多教程的预期方式使用URL。

I am using a Struts2 with the Restful plugin and Spring Security to serve and authenticate the website. 我正在使用带有Restful插件和Spring Security的Struts2来服务和认证网站。

So here's what's going on. 所以这是怎么回事。 I first was unable to get the <html> manifest attribute to give me absolute paths. 我首先无法获得<html>清单属性来给我绝对路径。 It seemed to always insist on being a relative one. 它似乎总是坚持要成为亲戚。

I worked around this by setting my header to something like this: 我通过将标头设置为以下方式来解决此问题:

 
 
 
 
  
  
  <html lang="en" manifest="0/appcache">
 
 
  

From here I added a function in my controller called "appcache" that serves a result that is a redirect to my appcache file. 从这里,我在控制器中添加了一个名为“ appcache”的函数,该函数提供的结果是重定向到我的appcache文件。

It is now correctly getting the proper url for the appcache, but it seems that it is treating all of the urls as relative paths from the current base url, rather than from the project root. 现在可以正确获取appcache的正确URL,但是似乎将所有URL都视为来自当前基本URL而不是项目根目录的相对路径。 As a result I am unable to use the correct urls for any of my files. 结果,我无法为我的任何文件使用正确的URL。

I am now just filling in the directory with a variable from the controller since this is using Tiles and I am unable to just have the manifest url written in the html its self. 我现在只用控制器中的变量填充目录,因为这使用的是Tiles,而我无法仅将清单网址写在html自身中。

I saw in many places that people were having firefox, but not in chrome, so I thought that may be the issue, however, it seems to be having the same issue in both places. 我在很多地方看到人们都在使用Firefox,但没有铬,所以我认为这可能是问题所在,但是,似乎在两个地方都存在相同的问题。

using the firefox command line tool, I can run the command: 'appcache validate' and get errors that look like the following: 使用firefox命令行工具,我可以运行命令:“ appcache validate”并获取类似于以下内容的错误:

 js/check-online.js points to a resource that is not available at line 10. 

And similarly in Chrome, I get the following error from the console: 同样在Chrome中,我从控制台收到以下错误:

 Application Cache Progress event (0 of 8) http://localhost:8080/WLS/inspection/0/js/check-online.js 

It appears that it is using some sort of URL pattern from of the manifest attribute to determine where to pull resources from, in fact if I change the '0' in the <html> to something else, chrome's output is updated to also behave in that way. 似乎它是使用manifest属性的某种URL模式来确定从何处提取资源,实际上,如果我将<html>的'0'更改为其他内容,则chrome的输出也会更新为在那样。

So, I think if I could get the manifest attribute to read from the root directory of the website, rather than doing what I'm doing now then I could move forward. 因此,我认为,如果我可以从清单的根目录中读取manifest属性,而不是现在做的事情,那么我可以继续前进。 Alternatively, I could possibly add functions in my controller for each file that I want to cache and that would also probably work, however that solution is very unattractive to me. 另外,我可以在控制器中为要缓存的每个文件添加函数,这也可能会起作用,但是该解决方案对我来说没有吸引力。 I think that there is something with Rest/Spring that is interfacing weirdly with the urls and causing the difficulties. 我认为Rest / Spring的某些内容与网址怪异地连接并造成了麻烦。

Without further Ado, here is the manifest file, though I don't suspect it to be overly relevant to the problems I'm having: 没有进一步的Ado,这是清单文件,尽管我不认为它与我遇到的问题过于相关:

 CACHE MANIFEST # vesion 6 NETWORK: onlineCheck.txt * CACHE: js/check-online.js styles/main.css styles/reveal.css styles/sectionsCustom.css styles/jquery.dataTables.css styles/jquery.selectBox.css offline/ FALLBACK: /user /offline /public /offline / /offline/404 

I am running out of ideas here. 我的想法在这里用光了。 Any help would be greatly appreciated. 任何帮助将不胜感激。 It seems that most tutorials and information I can find is either overly simplified to be useful, or old and outdated. 看来,我可以找到的大多数教程和信息要么过于简化以至无用,要么过时且过时。

Since posting this question, I have learned a lot about cache manifests. 自发布此问题以来,我已经学到了很多有关缓存清单的知识。 It turns out this is a dark world of sadness and trickery, however if you endeavor you can make it through alive. 事实证明,这是一个充满悲伤和诡计的黑暗世界,但是,如果您竭尽所能,就可以活下来。

I was doing several things fundamentally wrong, as well as some things in a manner that makes things more difficult than necessary. 我在做一些根本上是错误的事情,以及某些事情使事情变得比必要的困难。

So, what I have learned is this: 所以,我学到的是:

First of all, Firefox's command line tool's 'appcache validate' function seems to be broken, at least on mac. 首先,Firefox的命令行工具的“ appcache validate”功能似乎已损坏,至少在Mac上是如此。 It will load a different url than the page loads- possibly having to do with struts and stuff. 它将加载与页面加载不同的URL-可能与struts和东西有关。 Either way, this means that, while firefox and chrome both do the same thing, firefox's debugging tools say it's doing something else. 无论哪种方式,这都意味着,虽然firefox和chrome都做同样的事情,但是firefox的调试工具却说它在做其他事情。

Secondly, using struts to serve these files just makes things more difficult than necessary. 其次,使用struts服务这些文件只会使事情变得比必要的更加困难。 I can create a directory in my project root that contains any manifest files that I need, and then use that path directly. 我可以在项目根目录中创建一个目录,其中包含我需要的所有清单文件,然后直接使用该路径。 Again, due to the problems in firefox's appcache validate, this didn't appear to work on first glance, but it actually does. 再次,由于firefox的appcache validate的问题,乍一看似乎不起作用,但实际上确实如此。

Third off, and while I haven't seen this documented anywhere, I am relatively sure that it is the case, you can not have both the '*' and other content in the NETWORK: section. 第三,虽然我在任何地方都没有看到此文档,但我可以肯定的是,在NETWORK:部分中不能同时包含“ *”和其他内容。 It must be one or the other. 它必须是一个。 Otherwise, the '*' just seems to override anything else. 否则,“ *”似乎会覆盖其他任何内容。

Further thoughts. 进一步的想法。 I have found that, for my uses, this all works best by creating a very simple html page that only contains the manifest within an iframe as described in this article. 我发现,就我的用途而言,通过创建一个非常简单的html页面(如本文所述,该页面仅包含iframe中的清单),所有这些都可以最好地发挥作用 The writer also mentions Service Workers which should hopefully be less painful to use, however they are not yet around. 作者还提到了服务工作者 ,希望他们使用起来不会那么痛苦,但是还没有出现。 If anyone ends up reading this I would highly recommend checking to see if they are supported yet before going with AppCache as as solution. 如果有人最终阅读了这篇文章,我强烈建议您在使用AppCache作为解决方案之前先检查一下是否支持它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM