473,382 Members | 1,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Unable to cache style sheet

This really puzzles me. I have an application with a single style
sheet (30KB) and a series of js files, all declared in the header
section of the master page the standard way:
<link href="css/style1.css" rel="stylesheet" type="text/css"
media="screen"/>
<script src="js/common.js" type="text/javascript"></script
....

The css sheet is reloaded whenever a new page is accessed while the js
files remain cached. I experimented with downsizing the css file,
moving the css file in the root directoy to no avail. Obviously, I am
missing something here. How can I declaratively assign an expiration
date to the CSS file to prevent the browser from issuing reload
requests? TIA for any hints. (ASP.NET 3.5)
Jul 6 '08 #1
3 2990
Addendum. After noticing that the "Personal web site" starter kit
caches css files, I tried to duplicate this approach by creating a
subfolder (Theme1) in App_Themes and referencing it in web.config:
<pages styleSheetTheme="Theme1">.. </pages>

This improves rendering somewhat. Using YSlow, I noticed that all css/
js files have an expiration date and an Etag whenever the
ScriptManager is disabled. These attributes disappear when the
Scriptmanager is turned on. The css request issue persists in both
cases, however.

Thanks for sharing some ideas.
Jul 6 '08 #2
helveticus wrote:
This really puzzles me. I have an application with a single style
sheet (30KB) and a series of js files, all declared in the header
section of the master page the standard way:
<link href="css/style1.css" rel="stylesheet" type="text/css"
media="screen"/>
<script src="js/common.js" type="text/javascript"></script
...

The css sheet is reloaded whenever a new page is accessed while the js
files remain cached. I experimented with downsizing the css file,
moving the css file in the root directoy to no avail. Obviously, I am
missing something here. How can I declaratively assign an expiration
date to the CSS file to prevent the browser from issuing reload
requests? TIA for any hints. (ASP.NET 3.5)
I think that this is an issue with your specific instance of the web
browser, rather than an issue with the web application.

Normally css files are cached. Sometimes even more than you like, as you
have to rename the css file when you change it, to be sure that everyone
gets the new version.

--
Göran Andersson
_____
http://www.guffa.com
Jul 6 '08 #3
Thanks Göran.

I don't believe the problem is strictly browser related (although it
logically should). As mentioned above, a number of apps hosted on my
machine do cache stylesheet files in browser memory. No subsequent
css requests are issued when swapping pages. The problem is: I can't
see why it works in certain cases and fails in others..

I've narrowed the problem to css files. If a "good" ie cacheable css
file is imported in the App_Themes subfolder, the css file is cached.
As soon as I insert new css statements, the file becomes "bad" ie. non-
cacheable. This drives me nuts! I tried flushing the buffer cache,
changing names, etc. to no avail.

In php land, there seems to be a way to selectively enforce component
cacheability. For instance, I gleaned the following snippet from the
webmasterworld. php forum:
http://www.webmasterworld.com/apache/3659750.htm

This snippet apparently fully enforces cacheability of all css, gif,
png, etc. components. How can this be reproduced in asp.net? TIA for
any suggestions.

# Enable mod_expires
ExpiresActive on
# For media, css, pdf, and external Jscript files
<FilesMatch "\.(ico¦pdf¦flv¦jpe?g¦png¦gif¦js¦css¦swf)$">
# set 30-day cacheable (longer is almost useless)
ExpiresDefault A2592000
# Don't set any caching restrictions
Header unset Cache-Control
</FilesMatch>

Jul 7 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark | last post by:
Hi - I want to allow users of an intranet application, to select their own colours etc. So I have a tbale in my database, which has fields called bgcolour, fontcolour etc. As I want all pages...
2
by: Luke Bellamy | last post by:
Hi, I have been looking for a way to incorperate several different style sheets into a web page (i.e cascading effect). I have looked into the @import statement which seems to do what I want but...
5
by: Andrew Poulos | last post by:
If I have an external stylesheet that is @imported into my page and it has an element that looks like this: * html td { font-style: italic; } how can I use javascript to change the font...
7
by: Daniel Kaplan | last post by:
I have the item below at the top of my style sheet. And it seems that the font-szie is ignored. I know that my linked style sheet is being read, and used because if I remove the font-family line,...
8
by: pamelafluente | last post by:
Hi guys, Is it possible to add "onload" (via Javascript) a new class to the <styleheader section? If yes, how would that be done ? <style type="text/css" media="screen"> .NewStyleClass{...
10
by: pamelafluente | last post by:
Hi, this time I am trying to add a style on the fly.I wish equivalency with this one (only the menuItemStyle line): <head> <style type="text/css" media="screen"> ... some static styles ......
3
by: abid khan | last post by:
Hi, I've created a html page and also used a style sheet and a javascript file in this. all is good in internet explorer browser. but if i open this file in Mozilla firefox working of style sheet is...
4
by: fjm | last post by:
Hello everyone. I’d like to know how to handle multiple style sheets. I have css tabs that have a style sheet and then I also have a separate style sheet for the content that goes inside the tab. ...
4
Frinavale
by: Frinavale | last post by:
So a while ago I created a Tab Strip Control (before the AjaxToolkit had theirs otherwise I would have probably just used theirs). When I looked at the AjaxToolkit control to see how they got...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.