Clearing browser-cached content via javascript?

17 views
Skip to first unread message

Eric Patrick

unread,
Jul 13, 2011, 8:44:50 PM7/13/11
to MooTools Users
I have a "dashboarding" control that fetches a JSON representation of
a SQL cube via Request.JSON. For large cubes, my control has
options.cache which is passed to the server, and the server will
respond with a cache expiration header. This has worked out quite
well, as it elegantly leverages the browser's native caching
capability. The URI being cached is something like:

/DashboardService.asmx/JSON?procedure=MyDashboardProcedure&cache=600

I'd like to introduce the ability for a user to "force" a clearing of
this cached resource.

Training users to use Ctrl-F5 is both inelegant and inefficient, as it
would force an unnecessary reload of other cached items.

I could simply change the URI that I am calling, but the typical use
case is that a user want to get the 'refreshed' cube, and then keep
that current cube in cache for the default cache duration (600 seconds
in this example).

Any suggestions?

Thanks in advance,

Eric

Sean McArthur

unread,
Jul 14, 2011, 3:04:59 AM7/14/11
to mootool...@googlegroups.com

Whenever I wish to break cache, I include a nonce GET parameter.

'&nonce=' + (new Date()).getTime()

Eric Patrick

unread,
Jul 14, 2011, 9:37:03 AM7/14/11
to MooTools Users
That technique is workable, but a bit cumbersome in my use case. When
a user first navigates to a Dashboard page, the URI pulled would not
include the nonce parameter. Easy enough to have the 'refresh now'
command add the nonce.

However, the user will typically drill down to another page, leaving
the Dashboard page, only to return to the Dashboard page shortly
thereafter. At this point, the Dashboard page will load the 'default'
URI (without the nonce parameter).

So, I'd need to modify the control to track the 'nonce' URI across
page views (e.g. put it in a cookie; if the cookie exists, use it,
else use the 'default' URI). Certainly doable.

However, I was hoping for a slick version along the lines of new
Location(default URI).reload().

Thanks for the feedback!

Eric

On Jul 14, 3:04 am, Sean McArthur <sean.mons...@gmail.com> wrote:
> Whenever I wish to break cache, I include a nonce GET parameter.
>
> '&nonce=' + (new Date()).getTime()

Thierry bela nanga

unread,
Jul 14, 2011, 11:03:30 AM7/14/11
to mootool...@googlegroups.com
you can use window.location.reload(true) to reload the page from the server,

https://developer.mozilla.org/en/window.location
--
http://tbela99.blogspot.com/

fax : (+33) 08 26 51 94 51

Arieh Glazer

unread,
Jul 15, 2011, 9:14:53 AM7/15/11
to mootool...@googlegroups.com
A very nice technique that works on all browsers (but only for
resources from the same domain) is to do a PUT XMLHttpRequet:

new (XMLHttpRequest).open('PUT','path/to/resource',true).send();

not sure chaining works but this is sure to clear the resource from cache


--
Arieh Glazer
אריה גלזר
052-5348-561
http://www.arieh.co.il
http://www.link-wd.co.il

Reply all
Reply to author
Forward
0 new messages