Search code examples
.htaccessapplication-cacheservice-worker

Offline web application with rewritten URL's


Using the Application Cache I can easily make my web application available offline and it works perfectly. The problem I am encountering is that I have recently started using a .htaccess file to rewrite urls from

http://www.example.com/?/page

to

http://www.example.com/page

After loading the 'homepage' in principal everything still works (as all pages are loaded through Ajax), but local bookmarks and the like do not work. Is there any way to add this functionality with a simple service worker, whilst still relying on the Application Cache for the rest of the offline functionality (thus allowing Firefox and Safari to fall back on the Application Cache, whilst Chrome and Opera would work perfectly offline).


Solution

  • Browsers that support service workers* use the presence of a service worker as a trigger to disable App Cache functionality for pages under the service worker's scope. See Is Service Worker intended to replace or coexist with Appcache?

    I understand how using a service worker for something like rewriting URLs is independent from the offline use case, and therefore shouldn't interfere with App Cache, but there's no flag that you can use to say "Hey, this is a service worker that plays nicely with App Cache, so let me use both."

    * This applies to Google Chrome. As other browsers add support for service workers, they might have different policies with regard to App Cache.