How to Refresh CSS File on Every Page Request (no caching)

J

Jeremy S

How can I force a page to retrieve a fresh/new copy of a css file from the
Web server on *every* page request... GET and PostBacks?

I have tried this, but it seems to have no effect:
<%@ OutputCache Location="none" %>

Here is my situation:

Using ASP.NET 3.5, Web application, IE 7.0:

I have a basic master page implementation. In one of the content pages I
enable the user to save changes to classes in a css file. That content page
contains a link to the css file, like this:

<link href="../CustomClasses.css" type="text/css" rel="stylesheet" />

When the user saves changes to that css file via the aspx content page, I
would like for the page to retrieve a fresh copy of the newly-updated css
file and have those changes immediately reflected in the page.

One thought is to put this: <%@ OutputCache Location="none" %>
into the master page in addition to the content page, but the page will not
build, with a warning stating that the OutputCache Location directive is not
supported [in master pages].

Thoughts?

Thanks!
 
S

Sreenivas

How can I force a page to retrieve a fresh/new copy of a css file from the
Web server on *every* page request... GET and PostBacks?

I have tried this, but it seems to have no effect:
<%@ OutputCache Location="none" %>

Here is my situation:

Using ASP.NET 3.5, Web application, IE 7.0:

I have a basic master page implementation. In one of the content pages I
enable the user to save changes to classes in a css file. That content page
contains a link to the css file, like this:

<link href="../CustomClasses.css" type="text/css" rel="stylesheet" />

When the user saves changes to that css file via the aspx content page, I
would like for the page to retrieve a fresh copy of the newly-updated css
file and have those changes immediately reflected in the page.

One thought is to put this: <%@ OutputCache Location="none" %>
into the master page in addition to the content page, but the page will not
build, with a warning stating that the OutputCache Location directive is not
supported [in master pages].

Thoughts?

Thanks!

Dear Jeremy,

So your problem is changed CSS file is not applied for pages
after changing it through aspx page.You can inject the CSS link into
the Page header.But ,I don't know whether this approach overrides the
cached CSS in your browser? Anyway,give it a

try! let me know if this works.

The code goes something like this.

protected void Page_Load(object sender, EventArgs e)
{
CssInjection("./reddy.css");
}

void CssInjection(string url)
{
HtmlLink link = new HtmlLink();
link.Attributes["type"] = "text/css";
link.Attributes["href"] = url;
link.Attributes["rel"] = "stylesheet";
Page.Header.Controls.Add(link);
}
 
P

Paul Shapiro

If each user is getting a custom CSS file, you could save the modified
version with a distinctive file name, and then link that user's file into
the page. If they edit the css, append a version number to the file name.
That way each change is a new file to the browser so the cache gets
refreshed.
 
J

Jeremy S

Interesting idea. I might give it a try if nothing else works. My hesitance
is that this css file is not modified per user. The effect is site-wide (and
this admin page is accessible to only site admins). So while I'm sure it
would work, it seems like a lot of extra work that should be unnecessary for
my overall purposes.

What's confusing is that this page worked as intended when it was a .NET 1.1
app (with no master page involved). The <%@ OutputCache Location="none" %>
was honored. But now I have the same functionality in a 3.5 master page
scenario and it doesn't work... meaning that it seems to ignore the <%@
OutputCache Location="none" %> directive.

I would think this would be simple and easy; to accomplish in 3.5 master
page scenarios: force a refresh of a linked css file on *every* page
request.

-J







Paul Shapiro said:
If each user is getting a custom CSS file, you could save the modified
version with a distinctive file name, and then link that user's file into
the page. If they edit the css, append a version number to the file name.
That way each change is a new file to the browser so the cache gets
refreshed.

Jeremy S said:
How can I force a page to retrieve a fresh/new copy of a css file from
the Web server on *every* page request... GET and PostBacks?

I have tried this, but it seems to have no effect:
<%@ OutputCache Location="none" %>

Here is my situation:

Using ASP.NET 3.5, Web application, IE 7.0:

I have a basic master page implementation. In one of the content pages I
enable the user to save changes to classes in a css file. That content
page contains a link to the css file, like this:

<link href="../CustomClasses.css" type="text/css" rel="stylesheet" />

When the user saves changes to that css file via the aspx content page, I
would like for the page to retrieve a fresh copy of the newly-updated css
file and have those changes immediately reflected in the page.

One thought is to put this: <%@ OutputCache Location="none" %>
into the master page in addition to the content page, but the page will
not build, with a warning stating that the OutputCache Location directive
is not supported [in master pages].
 
J

Jesse Houwing

Hello Jeremy,
Interesting idea. I might give it a try if nothing else works. My
hesitance is that this css file is not modified per user. The effect
is site-wide (and this admin page is accessible to only site admins).
So while I'm sure it would work, it seems like a lot of extra work
that should be unnecessary for my overall purposes.

What's confusing is that this page worked as intended when it was a
.NET 1.1 app (with no master page involved). The <%@ OutputCache
Location="none" %> was honored. But now I have the same functionality
in a 3.5 master page scenario and it doesn't work... meaning that it
seems to ignore the <%@ OutputCache Location="none" %> directive.

I would think this would be simple and easy; to accomplish in 3.5
master page scenarios: force a refresh of a linked css file on *every*
page request.

You can go into IIS and change the caching settings for that specific foler.
And you can add any no-cache headers you want to the directoty, or the spcific
file.

As the CSS file isn't served by ASP.NET per se, it would be better to solve
the problem there.

Jesse

If each user is getting a custom CSS file, you could save the
modified version with a distinctive file name, and then link that
user's file into the page. If they edit the css, append a version
number to the file name. That way each change is a new file to the
browser so the cache gets refreshed.

How can I force a page to retrieve a fresh/new copy of a css file
from the Web server on *every* page request... GET and PostBacks?

I have tried this, but it seems to have no effect: <%@ OutputCache
Location="none" %>

Here is my situation:

Using ASP.NET 3.5, Web application, IE 7.0:

I have a basic master page implementation. In one of the content
pages I enable the user to save changes to classes in a css file.
That content page contains a link to the css file, like this:

<link href="../CustomClasses.css" type="text/css" rel="stylesheet"
/>

When the user saves changes to that css file via the aspx content
page, I would like for the page to retrieve a fresh copy of the
newly-updated css file and have those changes immediately reflected
in the page.

One thought is to put this: <%@ OutputCache Location="none" %>
into the master page in addition to the content page, but the page
will
not build, with a warning stating that the OutputCache Location
directive
is not supported [in master pages].
 
J

Jeremy S

You can go into IIS and change the caching settings for that specific
foler. And you can add any no-cache headers you want to the directoty, or
the spcific file.

As the CSS file isn't served by ASP.NET per se, it would be better to
solve the problem there.



That's good advice. It worked, and makes much more sense than trying to
accomplish it from the page directives (which was always troublesome).

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top