I'm finding that I need to implement a browser cache prevention scheme for dynamic content I am generating. My use case: user supplied info gets converted into XML and loaded by a java applet on the same page. I'm seeing the java applet load cached versions of the data, and I want to prevent this. I don't have the ability to modify the java applet, and it always loads it's XML from the same filename. I'm thinking about using the same technique that I see Drupal use for javascript files, where the src attribute's file url has a fake query string at the end, something like "/misc/drupal.js?5" , where the "?5" is the fake query string. It's my understanding that this prevents browser caching, and ultimately does not trigger a query - so it's a great method for cache prevention of dynamic content. Is my understanding correct? I've not done this before. Is it simply a matter of placing a single random character after the question mark? To anyone that has implemented a scheme such as this: any pitfalls I should be aware? Sincerely, -Blake bsenftner@earthlink.net www.BlakeSenftner.com www.MissingUbercartManual.com
That is only needed with actual files on disk, if your XML is returned from a Drupal menu callback, it's cache-expire headers should be set far in the past to prevent caching. Check this out with curl -v to see what's going on. -Mike __________________ Michael Prasuhn 503.512.0822 office mike@mikeyp.net http://mikeyp.net On Dec 9, 2010, at 1:05 PM, Blake Senftner wrote:
I'm finding that I need to implement a browser cache prevention scheme for dynamic content I am generating.
My use case: user supplied info gets converted into XML and loaded by a java applet on the same page.
I'm seeing the java applet load cached versions of the data, and I want to prevent this.
I don't have the ability to modify the java applet, and it always loads it's XML from the same filename.
I'm thinking about using the same technique that I see Drupal use for javascript files, where the src attribute's file url has a fake query string at the end, something like "/misc/drupal.js?5" , where the "?5" is the fake query string.
It's my understanding that this prevents browser caching, and ultimately does not trigger a query - so it's a great method for cache prevention of dynamic content.
Is my understanding correct? I've not done this before. Is it simply a matter of placing a single random character after the question mark? To anyone that has implemented a scheme such as this: any pitfalls I should be aware?
Sincerely, -Blake bsenftner@earthlink.net www.BlakeSenftner.com www.MissingUbercartManual.com
Thanks for the tip Mike. These are files on disk. Sincerely, -Blake bsenftner@earthlink.net www.BlakeSenftner.com www.MissingUbercartManual.com On Dec 9, 2010, at 1:09 PM, Michael Prasuhn wrote:
That is only needed with actual files on disk, if your XML is returned from a Drupal menu callback, it's cache-expire headers should be set far in the past to prevent caching. Check this out with curl -v to see what's going on.
-Mike __________________ Michael Prasuhn 503.512.0822 office mike@mikeyp.net http://mikeyp.net
On Dec 9, 2010, at 1:05 PM, Blake Senftner wrote:
I'm finding that I need to implement a browser cache prevention scheme for dynamic content I am generating.
My use case: user supplied info gets converted into XML and loaded by a java applet on the same page.
I'm seeing the java applet load cached versions of the data, and I want to prevent this.
I don't have the ability to modify the java applet, and it always loads it's XML from the same filename.
I'm thinking about using the same technique that I see Drupal use for javascript files, where the src attribute's file url has a fake query string at the end, something like "/misc/drupal.js?5" , where the "?5" is the fake query string.
It's my understanding that this prevents browser caching, and ultimately does not trigger a query - so it's a great method for cache prevention of dynamic content.
Is my understanding correct? I've not done this before. Is it simply a matter of placing a single random character after the question mark? To anyone that has implemented a scheme such as this: any pitfalls I should be aware?
Sincerely, -Blake bsenftner@earthlink.net www.BlakeSenftner.com www.MissingUbercartManual.com
Oops, that was a sales ticket, did it again and gave 789... Ayen Designs - quality software the first time, every time! -----Original Message----- From: Blake Senftner <bsenftner@earthlink.net> Sender: development-bounces@drupal.org Date: Thu, 9 Dec 2010 14:17:33 To: <development@drupal.org> Reply-To: development@drupal.org Subject: Re: [development] preventing browser cache Thanks for the tip Mike. These are files on disk. Sincerely, -Blake bsenftner@earthlink.net www.BlakeSenftner.com www.MissingUbercartManual.com On Dec 9, 2010, at 1:09 PM, Michael Prasuhn wrote:
That is only needed with actual files on disk, if your XML is returned from a Drupal menu callback, it's cache-expire headers should be set far in the past to prevent caching. Check this out with curl -v to see what's going on.
-Mike __________________ Michael Prasuhn 503.512.0822 office mike@mikeyp.net http://mikeyp.net
On Dec 9, 2010, at 1:05 PM, Blake Senftner wrote:
I'm finding that I need to implement a browser cache prevention scheme for dynamic content I am generating.
My use case: user supplied info gets converted into XML and loaded by a java applet on the same page.
I'm seeing the java applet load cached versions of the data, and I want to prevent this.
I don't have the ability to modify the java applet, and it always loads it's XML from the same filename.
I'm thinking about using the same technique that I see Drupal use for javascript files, where the src attribute's file url has a fake query string at the end, something like "/misc/drupal.js?5" , where the "?5" is the fake query string.
It's my understanding that this prevents browser caching, and ultimately does not trigger a query - so it's a great method for cache prevention of dynamic content.
Is my understanding correct? I've not done this before. Is it simply a matter of placing a single random character after the question mark? To anyone that has implemented a scheme such as this: any pitfalls I should be aware?
Sincerely, -Blake bsenftner@earthlink.net www.BlakeSenftner.com www.MissingUbercartManual.com
WE use this technique to stop IE from stubbornly caching swf files, etc. But if you don't have control of the URL that the java applet references, then you won't likely have much luck. The reason that this works is because it makes the urls different, so it doesn't see the cached version as the same fie. Rather than a random character, try including the file modification time so that it caches when it should and doesn't when it shouldn't. Something like: file.xml?ts=l12341242421 the number wold be the unix time stamp of the file modification time or the current timestamp if you want it to load every page. On Dec 9, 2010, at 2:17 PM, Blake Senftner wrote:
Thanks for the tip Mike. These are files on disk.
Sincerely, -Blake bsenftner@earthlink.net www.BlakeSenftner.com www.MissingUbercartManual.com
On Dec 9, 2010, at 1:09 PM, Michael Prasuhn wrote:
That is only needed with actual files on disk, if your XML is returned from a Drupal menu callback, it's cache-expire headers should be set far in the past to prevent caching. Check this out with curl -v to see what's going on.
-Mike __________________ Michael Prasuhn 503.512.0822 office mike@mikeyp.net http://mikeyp.net
On Dec 9, 2010, at 1:05 PM, Blake Senftner wrote:
I'm finding that I need to implement a browser cache prevention scheme for dynamic content I am generating.
My use case: user supplied info gets converted into XML and loaded by a java applet on the same page.
I'm seeing the java applet load cached versions of the data, and I want to prevent this.
I don't have the ability to modify the java applet, and it always loads it's XML from the same filename.
I'm thinking about using the same technique that I see Drupal use for javascript files, where the src attribute's file url has a fake query string at the end, something like "/misc/drupal.js?5" , where the "?5" is the fake query string.
It's my understanding that this prevents browser caching, and ultimately does not trigger a query - so it's a great method for cache prevention of dynamic content.
Is my understanding correct? I've not done this before. Is it simply a matter of placing a single random character after the question mark? To anyone that has implemented a scheme such as this: any pitfalls I should be aware?
Sincerely, -Blake bsenftner@earthlink.net www.BlakeSenftner.com www.MissingUbercartManual.com
Not to address the pitfalls question, but you can directly tap into the same mechanism JS & CSS files use by using this:
From http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_get_js...: $query_string = '?' . substr(variable_get('css_js_query_string', '0'), 0, 1);
On Thu, Dec 9, 2010 at 1:05 PM, Blake Senftner <bsenftner@earthlink.net> wrote:
prevents browser caching, and ultimately does not trigger a query - so it's a great method for cache prevention of dynamic content.
Thank you Adam. I was just about to go looking for that very same logic! Sincerely, -Blake bsenftner@earthlink.net www.BlakeSenftner.com www.MissingUbercartManual.com On Dec 9, 2010, at 1:12 PM, Adam B. Ross wrote:
Not to address the pitfalls question, but you can directly tap into the same mechanism JS & CSS files use by using this:
From http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_get_js...: $query_string = '?' . substr(variable_get('css_js_query_string', '0'), 0, 1);
On Thu, Dec 9, 2010 at 1:05 PM, Blake Senftner <bsenftner@earthlink.net> wrote:
prevents browser caching, and ultimately does not trigger a query - so it's a great method for cache prevention of dynamic content.
participants (5)
-
Adam B. Ross -
Blake Senftner -
David Metzler -
jeff@ayendesigns.com -
Michael Prasuhn