0

I've successfully implemented a HTML5 cache manifest file to store locally the pages and resources of my web app so that portions of it may be viewed while the user is offline.

The problem I'm running into, is that if the user starts on www.example.com/ and then navigates from there to www.example.com/products/, the links on the www.example.com/products/ page are broken (are missing part of the URL path) and revert to my FALLBACK offline page, indicating that they are not stored in the CACHE, although I explicitly told them to be stored.

Here's a section of my cache.manifest file:

CACHE MANIFEST
# Version 0.0.1

http://www.example.com/
http://www.example.com/products/
http://www.example.com/products/item-page/

FALLBACK:
/ http://www.example.com/offline.php

When I navigate to the products page from the home page, everything works as expected. When I then click the link to navigate to the item-page, the browser shows my offline.php page, indicating that http://www.example.com/products/item-page/ is not stored in the cache.

Am I missing something? Or why is this not working? Please help, and provide code/explanation :)

EDIT - I have .htaccess files redirecting my index.php pages to directory/ (to remove index.php from the URL). This seems to be causing the problem with the cache, because when I change my links in my HTML from item-page/index.php to item-page/ it works. Any ideas??

adamdehaven
  • 5,890
  • 10
  • 61
  • 84
  • Is your link definitely to `http://www.example.com/products/item-page/` and not `http://www.example.com/products/item-page`? – robertc Jul 12 '12 at 21:55
  • The link on http://www.example.com/product/ points to http://www.example.com/product/item-page/index.php – adamdehaven Jul 13 '12 at 00:06
  • 1
    But you don't have `example.com/product/item-page/index.php` in your manifest, why are you expecting it to be cached? – robertc Jul 13 '12 at 00:16
  • `example.com/products/item-page/index.php` IS in the manifest as `example.com/products/item-page/`. I leave off the `index.php` in the manifest because my `.htaccess` file redirects the `example.com/products/item-page/index.php` page to the `example.com/products/item-page/` – adamdehaven Jul 13 '12 at 13:32
  • No it isn't. For `example.com/product/item-page/index.php` to be in the manifest you have to actually put the URL `example.com/product/item-page/index.php` into it. As far as the browser is concerned `example.com/product/item-page/index.php` and `example.com/product/item-page/` are two different URLs, it can't make guesses about which URLs refer to the same server resources. Your `.htaccess` cannot redirect anything to anything if your server is offline. – robertc Jul 13 '12 at 13:35
  • If I type `example.com/product/item-page/index.php` the cache.manifest file fails (view with Safari Web Inspector) because it says `example.com/product/item-page/index.php was redirected` so the manifest file is not created. – adamdehaven Jul 13 '12 at 16:56
  • 2
    So don't redirect it, or link directly to the URL that you want instead of to a URL you don't want to use. – robertc Jul 13 '12 at 17:09

2 Answers2

1

Your server redirects item-page/ to item-page/index.php, and redirects are not automatically cached.

You should

  1. Add item-page/index.php to your manifest, in addition to item-page (they are actually two pages), or
  2. Make item-page/ load the content you have for index.php, without the redirect
Maarten
  • 6,894
  • 7
  • 55
  • 90
0

If you add this section to your manifest file it should work

NETWORK:
*
agez
  • 624
  • 1
  • 7
  • 17
  • All this does is include all files that are not specifically outlined in the manifest, and allows the cache of pages that contain the manifest in the `` tag. – adamdehaven Jul 16 '12 at 12:25