Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Custom image url does not use cachebreaker #20

Open
cristiano-belloni opened this issue Nov 5, 2013 · 3 comments
Open

Custom image url does not use cachebreaker #20

cristiano-belloni opened this issue Nov 5, 2013 · 3 comments

Comments

@cristiano-belloni
Copy link

Hi all,
I'm trying to set a custom image URL in the Offline.options. Just to test, I'm using the same cloudfront gif Offline uses, but with https because I host an ssl site.

Offline.options = {checks: {image: {url: 'https://dqakt69vkj09v.cloudfront.net/are-we-online.gif'}}};

The problem seems to be that, with a custom image url, there seems to be no "cachebreaker" query string, while I can see it with the default image url. This makes the browser respond a 304 - not modified and offline.js stops detecting a connection lost.

Please note that the problem is not https. Even with this gif, the cachebreaker is not sent and offline does not work:

Offline.options = {checks: {image: {url: 'http://dqakt69vkj09v.cloudfront.net/are-we-online.gif'}}};
@cristiano-belloni
Copy link
Author

Looking at the code, the problem seems to be that the cachebreaker is only built in the default options:

return "http://dqakt69vkj09v.cloudfront.net/are-we-online.gif?_=" + (Math.floor(Math.random() * 1000000000));

There should be a separate cachebreaker option also for all kind of urls, imho (default and custom).

@zackbloom
Copy link
Contributor

Yea, it was originally not included because cache breaking in different methods might differ. Nevertheless, jQuery does it using underscore, so it's a good idea.

@theremon
Copy link

I had the same issue. Solved it by simply setting the url property to a function instead of a string:
url: function() { return "image.gif?_=" + (Math.floor(Math.random() * 1000000000)); }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants