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.
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.
I am using a Struts2 with the Restful plugin and Spring Security to serve and authenticate the website.
So here's what's going on. I first was unable to get the <html>
manifest attribute to give me absolute paths. 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.
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. As a result I am unable to use the correct urls for any of my files.
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.
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.
using the firefox command line tool, I can run the command: 'appcache validate' and get errors that look like the following:
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:
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.
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. 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.
Without further Ado, here is the manifest file, though I don't suspect it to be overly relevant to the problems I'm having:
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. It will load a different url than the page loads- possibly having to do with struts and stuff. Either way, this means that, while firefox and chrome both do the same thing, firefox's debugging tools say it's doing something else.
Secondly, using struts to serve these files just makes things more difficult than necessary. 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.
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. 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. 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.