PC Review


Reply
Thread Tools Rate Thread

How can I prevent Caching of JavaScript and CSS files ONLY when I deploy a new application?

 
 
mark4asp
Guest
Posts: n/a
 
      15th Oct 2007
How can I prevent Caching of JavaScript and CSS files ONLY when I
deploy a new application? I only want to force a refresh the first
time the client uses the new build.

For instance, I'm told I can do it with javascript by including a
version number as a querystring like this:
<script type="text/javascript" src="../javascript/menu.js?v=2"></
script>

However that won't solve the problem of the css files.

 
Reply With Quote
 
 
 
 
Larry Bud
Guest
Posts: n/a
 
      15th Oct 2007
On Oct 15, 9:26 am, mark4asp <mark4...@gmail.com> wrote:
> How can I prevent Caching of JavaScript and CSS files ONLY when I
> deploy a new application? I only want to force a refresh the first
> time the client uses the new build.
>
> For instance, I'm told I can do it with javascript by including a
> version number as a querystring like this:
> <script type="text/javascript" src="../javascript/menu.js?v=2"></
> script>
>
> However that won't solve the problem of the css files.


If the file has changed, why would it used the cached copy?

 
Reply With Quote
 
mark4asp
Guest
Posts: n/a
 
      15th Oct 2007
On 15 Oct, 14:55, Larry Bud <larrybud2...@yahoo.com> wrote:
> On Oct 15, 9:26 am, mark4asp <mark4...@gmail.com> wrote:
>
> > How can I prevent Caching of JavaScript and CSS files ONLY when I
> > deploy a new application? I only want to force a refresh the first
> > time the client uses the new build.

>
> > For instance, I'm told I can do it with javascript by including a
> > version number as a querystring like this:
> > <script type="text/javascript" src="../javascript/menu.js?v=2"></
> > script>

>
> > However that won't solve the problem of the css files.

>
> If the file has changed, why would it used the cached copy?


If a client or proxy has the "menu.js" cached then it will continue to
use
it until (a) the headers in the menu.js change (which can only be done
in
IIS as I understand it) or (b) the user refreshes the browser (e.g.
with an F5)

- this will make the page look like a dogs dinner (or worse) if I
change that
file when deploying a new application - that's a huge problem. I want
to
maximise the client caching of files whist ensuring that cached files
are
always updated on becoming obsolete.

 
Reply With Quote
 
bruce barker
Guest
Posts: n/a
 
      15th Oct 2007
the easiest is to change the name or folder, by appending the version.
cleaner than fake query strings.

-- bruce (sqlwork.com)



mark4asp wrote:
> How can I prevent Caching of JavaScript and CSS files ONLY when I
> deploy a new application? I only want to force a refresh the first
> time the client uses the new build.
>
> For instance, I'm told I can do it with javascript by including a
> version number as a querystring like this:
> <script type="text/javascript" src="../javascript/menu.js?v=2"></
> script>
>
> However that won't solve the problem of the css files.
>

 
Reply With Quote
 
mark4asp
Guest
Posts: n/a
 
      15th Oct 2007
On 15 Oct, 16:28, bruce barker <nos...@nospam.com> wrote:
> the easiest is to change the name or folder, by appending the version.
> cleaner than fake query strings.
>
> -- bruce (sqlwork.com)
>
> mark4asp wrote:
> > How can I prevent Caching of JavaScript and CSS files ONLY when I
> > deploy a new application? I only want to force a refresh the first
> > time the client uses the new build.

>
> > For instance, I'm told I can do it with javascript by including a
> > version number as a querystring like this:
> > <script type="text/javascript" src="../javascript/menu.js?v=2"></
> > script>

>
> > However that won't solve the problem of the css files.


Is there anything wrong with adding a querystring to the .css and .js
files?
It seems to me far easier than the other suggested methods: a) if I
append a querystring to the folder name, the client end up with
potentially lots of folders containing my obsolete code and it's also
more inconvenient for me. If I append a querystring to the filename
likewise then client still has the obsolete files cached.

 
Reply With Quote
 
Rad [Visual C# MVP]
Guest
Posts: n/a
 
      15th Oct 2007
On Mon, 15 Oct 2007 08:28:02 -0700, bruce barker <(E-Mail Removed)>
wrote:

>the easiest is to change the name or folder, by appending the version.
>cleaner than fake query strings.
>
>-- bruce (sqlwork.com)


I'm curious -- I don't see the drawback to the quasi query strings. If
anything they'd save the clutter of numerous folders for different
deployments

--
http://bytes.thinkersroom.com
 
Reply With Quote
 
mark4asp
Guest
Posts: n/a
 
      16th Oct 2007
On 15 Oct, 18:31, "Rad [Visual C# MVP]" <r...@nospam.com> wrote:
> On Mon, 15 Oct 2007 08:28:02 -0700, bruce barker <nos...@nospam.com>
> wrote:
>
> >the easiest is to change the name or folder, by appending the version.
> >cleaner than fake query strings.

>
> >-- bruce (sqlwork.com)

>
> I'm curious -- I don't see the drawback to the quasi query strings. If
> anything they'd save the clutter of numerous folders for different
> deployments
>
> --http://bytes.thinkersroom.com


With the querystring version the only work needed is to add 1 to the
Build version in config.sys each time you deploy the new build.

web.config entry:

<appSettings>
<add key="BuildVersion" value="1"/>
</appSettings>

Global entry:

public static readonly string Build =
(string)ConfigurationManager.AppSettings["BuildVersion"];

Individual page entries:

<link type="text/css" rel="stylesheet" href="../images/menu.css?v=<
%=MyNS.Global.Build %>" />
<script type="text/javascript" src="../javascript/browser.js?v=<
%=MyNS.Global.Build %>"></script>

Seems like the way to go to me. Could anything be simpler than this?

 
Reply With Quote
 
mark4asp
Guest
Posts: n/a
 
      16th Oct 2007
On 15 Oct, 18:31, "Rad [Visual C# MVP]" <r...@nospam.com> wrote:
> On Mon, 15 Oct 2007 08:28:02 -0700, bruce barker <nos...@nospam.com>
> wrote:
>
> >the easiest is to change the name or folder, by appending the version.
> >cleaner than fake query strings.

>
> >-- bruce (sqlwork.com)

>
> I'm curious -- I don't see the drawback to the quasi query strings. If
> anything they'd save the clutter of numerous folders for different
> deployments
>
> --http://bytes.thinkersroom.com


With the querystring version the only work needed is to add 1 to the
Build version in config.sys each time you deploy the new build.

web.config entry:

<appSettings>
<add key="BuildVersion" value="1"/>
</appSettings>

Global entry:

public static readonly string Build =
(string)ConfigurationManager.AppSettings["BuildVersion"];

Individual page entries:

<link type="text/css" rel="stylesheet" href="../images/menu.css?v=<
%=MyNS.Global.Build %>" />
<script type="text/javascript" src="../javascript/browser.js?v=<
%=MyNS.Global.Build %>"></script>

Seems like the way to go to me. Could anything be simpler than this?

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
vs 2008 WinForm application deploy to client C:\Program Files folder Jason Huang Microsoft C# .NET 1 18th Sep 2009 09:44 AM
How to deploy console application - what files are necessary? Corey B Microsoft Dot NET Framework 0 20th Jul 2007 05:56 PM
HOW CAN I PREVENT MY VB.NET APPLICATION FROM CACHING BY IIS Savas Ates Microsoft VB .NET 2 20th Jan 2006 12:55 PM
How do I prevent powerpoint from caching temporary files =?Utf-8?B?cGllVg==?= Microsoft Powerpoint 4 5th Oct 2004 03:24 PM
caching large XML files in an ASP.net application spammy Microsoft ASP .NET 3 21st May 2004 08:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:28 AM.