Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mark4asp - 15 Oct 2007 14:26 GMT
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.
Larry Bud - 15 Oct 2007 14:55 GMT
> 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
[quoted text clipped - 6 lines]
>
> However that won't solve the problem of the css files.

If the file has changed, why would it used the cached copy?
mark4asp - 15 Oct 2007 15:34 GMT
> > 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
[quoted text clipped - 8 lines]
>
> 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.
bruce barker - 15 Oct 2007 16:28 GMT
the easiest is to change the name or folder, by appending the version.
cleaner than fake query strings.

-- bruce (sqlwork.com)

> 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
[quoted text clipped - 6 lines]
>
> However that won't solve the problem of the css files.
mark4asp - 15 Oct 2007 18:04 GMT
> the easiest is to change the name or folder, by appending the version.
> cleaner than fake query strings.
[quoted text clipped - 11 lines]
>
> > 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.
Rad [Visual C# MVP] - 15 Oct 2007 18:31 GMT
>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
mark4asp - 16 Oct 2007 14:10 GMT
> >the easiest is to change the name or folder, by appending the version.
> >cleaner than fake query strings.
[quoted text clipped - 6 lines]
>
> --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?
mark4asp - 16 Oct 2007 14:13 GMT
> >the easiest is to change the name or folder, by appending the version.
> >cleaner than fake query strings.
[quoted text clipped - 6 lines]
>
> --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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.