473,796 Members | 2,609 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I get browser to cache images, css etc..?

Hi,

I have a site were the pages are dynamically generated on demand.
These pages like any static html page may contain image tags and
references to CSS files.

All the images and CSS files etc... are stored in a database so in the
HTML produced for the page the source of an image, for example,
might be:
src=http://www.mysite.com/Res/3/logo.gif

The DLL that runs my site contains a HttpModule that parses each
request when it sees a URL with Res/X/filename in it it extracts the
number X and uses it and the filename to lookup the data in the
database and then does a Response.Write or Response.Binary Write
depending on the type of data.

Before it actually writes the data back to the browser it:

With Response
.Expires = 0
.Buffer = True
.Clear()
.AddHeader("Las t-modified",..... .)
.ContentType = Ctype(....., string)
.Cache.SetCache ability(HttpCac heability.Publi c)
.AddHeader("con tent-disposition", "filename=" & ....)

.... the decisision of either .Write or .BinaryWrite
End With

However I can see when running through VS.NET that each
time the you visit the page the images etc... are reloaded.
This makes it even worse when you try to load JS to preload
images for roll-over effects, as this JS actually has no effect
and both over and off images a reloaded everytime.

Anybody have any ideas?

Regards,
Peter
Nov 18 '05 #1
2 2162
You set Expires to 0, which will cause the browser to request the image from
the server every time.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Peter Row" <pe*******@oxfo rdcc.co.uk> wrote in message
news:Os******** ******@TK2MSFTN GP11.phx.gbl...
Hi,

I have a site were the pages are dynamically generated on demand.
These pages like any static html page may contain image tags and
references to CSS files.

All the images and CSS files etc... are stored in a database so in the
HTML produced for the page the source of an image, for example,
might be:
src=http://www.mysite.com/Res/3/logo.gif

The DLL that runs my site contains a HttpModule that parses each
request when it sees a URL with Res/X/filename in it it extracts the
number X and uses it and the filename to lookup the data in the
database and then does a Response.Write or Response.Binary Write
depending on the type of data.

Before it actually writes the data back to the browser it:

With Response
.Expires = 0
.Buffer = True
.Clear()
.AddHeader("Las t-modified",..... .)
.ContentType = Ctype(....., string)
.Cache.SetCache ability(HttpCac heability.Publi c)
.AddHeader("con tent-disposition", "filename=" & ....)

.... the decisision of either .Write or .BinaryWrite
End With

However I can see when running through VS.NET that each
time the you visit the page the images etc... are reloaded.
This makes it even worse when you try to load JS to preload
images for roll-over effects, as this JS actually has no effect
and both over and off images a reloaded everytime.

Anybody have any ideas?

Regards,
Peter

Nov 18 '05 #2
Hi,

Doh!
Yes that's right, plus I hadn't upgraded the code to use the prefered
Cache object property instead of the compatibility property Expires.

This was a porting job from VB6 webclasses.

Thanks for the reply,

Regards,
Peter
"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:eh******** ******@TK2MSFTN GP12.phx.gbl...
You set Expires to 0, which will cause the browser to request the image from the server every time.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Peter Row" <pe*******@oxfo rdcc.co.uk> wrote in message
news:Os******** ******@TK2MSFTN GP11.phx.gbl...
Hi,

I have a site were the pages are dynamically generated on demand.
These pages like any static html page may contain image tags and
references to CSS files.

All the images and CSS files etc... are stored in a database so in the
HTML produced for the page the source of an image, for example,
might be:
src=http://www.mysite.com/Res/3/logo.gif

The DLL that runs my site contains a HttpModule that parses each
request when it sees a URL with Res/X/filename in it it extracts the
number X and uses it and the filename to lookup the data in the
database and then does a Response.Write or Response.Binary Write
depending on the type of data.

Before it actually writes the data back to the browser it:

With Response
.Expires = 0
.Buffer = True
.Clear()
.AddHeader("Las t-modified",..... .)
.ContentType = Ctype(....., string)
.Cache.SetCache ability(HttpCac heability.Publi c)
.AddHeader("con tent-disposition", "filename=" & ....)

.... the decisision of either .Write or .BinaryWrite
End With

However I can see when running through VS.NET that each
time the you visit the page the images etc... are reloaded.
This makes it even worse when you try to load JS to preload
images for roll-over effects, as this JS actually has no effect
and both over and off images a reloaded everytime.

Anybody have any ideas?

Regards,
Peter


Nov 18 '05 #3

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

Similar topics

21
3268
by: Tony Marston | last post by:
If the use of the browser's BACK button is interfering with the operation of your web application then take a look at this article entitle "Back Button Blues" http://www.tonymarston.co.uk/php-mysql/backbuttonblues.html -- Tony Marston http://www.tonymarston.net
9
2211
by: Cyrus D. | last post by:
Hi guys, Let's say I have a page that is primarily HTML but I added a few small parts that are PHP, for example a random banner. The page is in no way PHP driven, it just has some some random stuff like the banner and/or a tip of the day. What bothers me is that the PHP page won't be cached, so if the page has a lot of links and, on average, the user clicks ten links (hitting the back button after he does that) my bandwidth usage...
2
474
by: Peter Row | last post by:
Hi, I have a site were the pages are dynamically generated on demand. These pages like any static html page may contain image tags and references to CSS files. All the images and CSS files etc... are stored in a database so in the HTML produced for the page the source of an image, for example, might be: src=http://www.mysite.com/Res/3/logo.gif
4
1789
by: Charlie | last post by:
Hi: When I change an image, but keep same title, then upload image to hosting server, my browser will display old image until I refresh. If I close browser, then open same page again, I have to refresh again to view new image. It's not until I have done this a few times will get new image without refreshing. Seems like browser is somehow holding on to old image. Anyone know what causes this and how to prevent it? Thanks,
5
2194
by: Haydnw | last post by:
Hi, I have the code below as code-behind for a page which displays two images. My problem is with the second bit of code, commented as " 'Portfolio image section". Basically, the SQL query gets details of a random image from an access database. I know this works because when I run the query in access, it picks a different image each time (or close enough). However, when I view the .aspx page that this code-behind is for, it always picks...
9
3349
by: WRH | last post by:
Hello I am new to asp but I made some Jscript functions which work fine. The functions contain some strings used as a registration key for some apps. It is important that these strings not be visible to a client using a browser. My question is...can a knowledgeable browser user view Jscript source code in an asp file?
3
1436
by: Joe Fallon | last post by:
I have a page in ASP.Net 1.1 which contains an image control. I set the ImageUrl property = "MyImageViewerPage.aspx" This page acts as an image handler. I have an array of bytes which I send to the browser using BinaryWrite. e.g. Response.ContentType = mVar.contenttype Response.BinaryWrite(mVar.MyBytes)
1
1875
by: emer.kurbegovic | last post by:
Is it possible to cache dynamic images in client's browser the same way static images are cached? for example, i'd like to be able to cache this dynamic image: <img src=pic.axd?id=2the same way the browser would cache it if it would say <img src=http://someplace.com/pic.jpg> is this possible? if not, what are my choices/alternatives? thanks in advance,
0
1477
by: etnaelk | last post by:
Hi all, I have a real bugger of a problem that I just haven't been able to figure out. I am working on writing my own proxy server in C# using TcpListener, TcpClient, HttpWebRequest/Response and NetworkStream. I have everything working pretty well except images won't load to their location. ------------------------------------------------------------------------------------------------------------------...
0
9535
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6800
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5453
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4127
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.