Search code examples
javascriptdatehashlocationsammy.js

SammyJS IE setLocation Caching


When I trigger set location with SammyJS, IE seems to cache the url and it doesn't trigger the route. To get around this I've added a date string to the end of my route:

var d = Date.now();
sammy.setLocation("#location" + d);

Is there a better way to fix this issue without the addition of a date string?


Solution

  • IE9 and before will cache GET requests. (I don't think this happens in IE>=10, but feel free to correct me.) Also, if memory serves, IE<=9 is not the only browser that does this - Safari (don't have the versions in front of me, but I don't think newer versions will behave this way) will also do this. I think it's done in an effort to save round-trips and bandwidth.

    That said, there are a couple of options to try to hack around it:

    • What you're already doing. I've seen tacking in the date stamp as a querystring parameter to a get request to get around this issue done. It works, but it can feel hacky.
    • No cache header. You can send back a no cache header with an expiration date in the past. This will force the browser to re-request the resource. I don't know if this is doable from within Sammy itself, but if you're issuing a GET back to the server, it might be worth a shot. (I'd be curious if this works.)
    • Use a POST instead. POSTs are not cached. Not sure if this is an option in your particular scenario, but worth mentioning.