0

I tried to execute the following set of coding which is already in w3schools

index.html has the following codings

<!DOCTYPE html>
     <html manifest="demo_html.appcache">
          <body>
             <script src="demo_time.js"></script>
                  <p id="timePara"><button onclick="getDateTime()">Get Date and Time</button></p>
                  <p><img src="logo.jpeg" width="336" height="69"></p>
                  <p>Try opening <a href="index.html" target="_blank">this page</a>, then go offline, and reload the page. The script and the image should still work.</p>
            </body>
      </html>

demo_time.js contains the following

 function getDateTime()
 {
       var d=new Date();
       document.getElementById('timePara').innerHTML=d;
 }

demo_html.appcache contains the following

 CACHE MANIFEST

 CACHE:
 /index.html
 /demo_time.js
 /logo.jpeg

".htaccess" file contains the following

 AddType text/cache-manifest .appcache

Please point out the mistake in this code. When i executed the code in my browser, firefox prompted me to This website is asking to store data on your computer for offline use. Allow, never for this site or not now. I choose Allow, but the prompt did not disappear even then.

When i tried the same in w3schools.com, the prompt disappeared after i clicked Allow. Please point out the mistake in the above code

  • Have you checked in the content type of the request that your `.htaccess` file is working? Do you have these files uploaded to a server we could look at? – robertc Dec 24 '12 at 14:24
  • i got it working without .htaccess after uploading it to server – user1619303 Dec 26 '12 at 10:12

2 Answers2

0

Offline cache only works for remote files. When you run the page locally, it won't actually offline the files.

If you access your page via a server, you should see the offline cache working.

Fenton
  • 241,084
  • 71
  • 387
  • 401
0

I changed the demo_html.appcache to the simpler

CACHE MANIFEST
index.html
demo_time.js
logo.jpeg

and that works for me in both firefox and chrome

Chromes "Resources" tab is really helpful for debugging the appcache:

screenshot of chromes resources-tab

bjelli
  • 9,752
  • 4
  • 35
  • 50