Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 cache manifest: unsuccessful ajax calls getting fallback

I've got an HTML5 application which uses a cache manifest to provide offline functionality. This application makes ajax calls, when online, and some of this calls can obtain a 403 unauthorized in response.

Here's the bottom of my cache.manifest file:

NETWORK:
*

FALLBACK:
/ /offline

If I remove the fallback section, all the ajax calls receiving a 403 response work as expected and I can detect this with jQuery error handler and redirect the user to the login form.

But if fallback section is present, the same calls get a 200 OK response, with fallback HTML's content as body, even though the server replied with a 403, so there's no way for me to know the user is not authenticated and must be sent to the login page.

Am I missing something here? Thanks in advance

like image 886
Jonathan Naguin Avatar asked Jun 04 '12 10:06

Jonathan Naguin


People also ask

What is fallback in application cache?

FALLBACK: An optional section specifying fallback pages if a resource is inaccessible. The first URI is the resource, the second is the fallback used if the network request fails or errors. Both URIs must from the same origin as the manifest file. You can capture specific URLs but also URL prefixes.

What is a manifest file in HTML5?

The manifest file is a simple text file that lists the resources the browser should cache for offline access. To learn more about how to create the manifest file, please read our HTML5 Application Cache chapter.


1 Answers

Adding a random number as query-parameter to the page you're looking for to the jQuery-AJAX will solve the issue; i.e.

$.ajax({
  url: "/data.html?"+ Math.random(),
  // other properties here...
});
like image 110
Debloper Avatar answered Oct 06 '22 01:10

Debloper