Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IE does not reload css or js file...

2 views
Skip to first unread message

Matthew Wells

unread,
May 3, 2008, 1:12:22 PM5/3/08
to
Hello,

I'm working on an ASP.net 2.0 web project using VS 2005. I'm on my laptop
running IIS on WinXP SP2 with all the latest updates. The Default web site
is set to run on .net 2.0 My project uses a master page.

I have two separate issues that I think are related.

First, I can't figure out why changes to my CSS don't load when I start the
project. The css is in the master page. The CSS loads, but only the last
version I hit F5 for. I always have to hit F5 to see the changes. I set
the IE option to Check for newer versions of stored pages every time I visit
the webpage. Yes I closed all instances of IE and even rebooted for good
measure. No luck.

Second, I can't get javascript to work when it's being called using the src
attribute. I use

<script type="text/javascript" src="test.js" ></script>

test.js is in the same folder as test.aspx, which calls it. I stripped
everything out of the files - even the code-behind file. All that's in the
.js file is an alert function. The only thing on the web form is a button
that calls the function using OnClientClick. It works if I put the function
in the web form so I know javascript works. I had a brief moment of success
when it worked - I thought - but it was having the same problem as the CSS -
It would not show the latest changes without hitting F5. I would make the
message "aaaaa" and start the project, hit F5 and see "aaaaa". I'd stop the
project, change the message to "bbbbb", start the project and still see
"aaaaa" until I hit F5 and see "bbbbb".

This is why I think the CSS and javascript problems are related.

Does anyone know why this is happening?

Thanks.

Matthew Wells
Matthe...@FirstByte.net


Fernando Rodriguez, MCP

unread,
May 3, 2008, 10:49:26 PM5/3/08
to
Try adding a Global.asax file and on it's Application_BeginRequest method
add the following:

HttpContext.Current.Response.Expires = 0;
HttpContext.Current.Response.ExpiresAbsolute = DateTime.Now.AddDays(- 2);
HttpContext.Current.Response.CacheControl = "private";
HttpContext.Current.Response.AddHeader("pragma", "no-cache");

That should prevent your browser from caching any files.

I'm pretty sure it will also affect the .js and .css files when you load
them from an ASPX page, but if it doesn't you can just rename your .js and
.css files to .aspx and it will be fine.

Hope that helps,
Fernando L Rodriguez, MCP

"Matthew Wells" <Matthe...@FirstByte.net> wrote in message
news:CIWdnYVmlfhqAYHV...@comcast.com...

David

unread,
May 4, 2008, 4:54:45 AM5/4/08
to
This is just down to caching. If your JS and CSS files are not dynamic, then
when on your site, it shouldn't be an issue...

However, when you run the project from VS, if the files are not there, then
simply press and hold your CTRL key whilst you press the refresh button (or
press CTRL-F5 whilst browser is focussed).

This will get you the latest version.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


"Matthew Wells"

Matthew Wells

unread,
May 4, 2008, 1:19:30 PM5/4/08
to
The files are there and as I said everything works after I hit F5 or Ctrl
F5. I've also started the project using Ctrl F5. I'm going to try the
suggestion in the first reply, but I shouldn't have to go through that.
I'll let you know.

Thanks.


"David" <david.col...@revilloc.REMOVETHIS.com> wrote in message
news:%23uCDVSc...@TK2MSFTNGP03.phx.gbl...

David

unread,
May 4, 2008, 5:16:53 PM5/4/08
to
No, not starting the project with ctrl-f5, but just press ctrl-f5 in your
browser to force it to download the latest (uncached) files.

bruce barker

unread,
May 5, 2008, 12:14:27 AM5/5/08
to
a f5 in IE will not reload css or javascript files that are caches. you
must delete the cache.

switch to firefox and the developer extension, you can flip a setting to
reload javascript and css while debugging. if you must use IE, then load
its dev toolbar, at least it has a button to delete cache.

-- bruce (sqlwork.com)

fd12...@hotmail.com

unread,
May 5, 2008, 12:55:15 PM5/5/08
to
I believe his problem is not on his browser's side but on his server's
side. IIS will cache the css stylesheet and will not always detect
when it's changed (i.e. if the file is programmatically modified
instead of copied/deleted/created).

To disable CSS caching (and most of the caching mechanisms, be
warned...), on the server, create the following registry key :

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\HTTP\Parameters
\UriEnableCache

...and set it to 0 (zero).

This works on IIS 7, don't know about other versions but it's worth a
try.

Don't know if it will help with the js problem, though.

Warning : always make a backup of the registry before editing, be
extra careful if it's a production server, etc, you know the drill.

HTH,

Michel

> Matthew.We...@FirstByte.net

Matthew Wells

unread,
May 5, 2008, 4:09:54 PM5/5/08
to
This one worked at first. I remmed out the lines and it failed. Then I
unremmed them and it still didn't work. Still can't get it to refresh
without manually hitting F5.


"Fernando Rodriguez, MCP" <frodri...@hotmail.com> wrote in message
news:481d2463$0$3361$4c36...@roadrunner.com...

Matthew Wells

unread,
May 8, 2008, 8:51:02 AM5/8/08
to
This one seemed to wokrk!!!! Thanks!!!! There is still a timing issue with
javascript, but I'll put that one in a separate post.

Matthew Wells
Matthe...@FirstByte.net


<fd12...@hotmail.com> wrote in message
news:801b3f79-9060-4f8c...@2g2000hsn.googlegroups.com...

0 new messages