Go Back   CodingForums.com > :: Client side development > General web building

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-04-2012, 01:27 AM   PM User | #1
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 640
Thanks: 20
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
Prevent Caching??

Is there a way to prevent images (or content) from being cached on a user's computer?


Debbie
doubledee is offline   Reply With Quote
Old 10-04-2012, 03:27 AM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,530
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
The simplest way to do that if you have access to a server side language is to simply add a header to tell the browser not to cache the file.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 10-04-2012, 06:12 PM   PM User | #3
patryk
Regular Coder

 
patryk's Avatar
 
Join Date: Oct 2012
Location: /dev/couch
Posts: 395
Thanks: 2
Thanked 64 Times in 64 Posts
patryk is on a distinguished road
without getting into setting headers, you can add different GET data each time image is downloaded.
for example if url of image is http://example.com/pic.png, you can access it using http://example.com/pic.png?q=1, http://example.com/pic.png?q=2, http://example.com/pic.png?q=3, and so on.
this way each rime you have diferent url, and browser will download image every time
patryk is offline   Reply With Quote
Old 10-07-2012, 07:24 PM   PM User | #4
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 640
Thanks: 20
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
Quote:
Originally Posted by felgall View Post
The simplest way to do that if you have access to a server side language is to simply add a header to tell the browser not to cache the file.
Okay, some follow up questions...

1.) How reliable is that?

2.) Will it work equally well in any Server-side Language (e.g. .Net, PHP, etc.)?

3.) Will it work equally well across Browsers (e.g. Internet Explorer, FireFox, Chrome, etc.)?

Thanks,


Debbie
doubledee is offline   Reply With Quote
Old 10-07-2012, 07:26 PM   PM User | #5
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 640
Thanks: 20
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
Quote:
Originally Posted by patryk View Post
without getting into setting headers, you can add different GET data each time image is downloaded.
for example if url of image is http://example.com/pic.png, you can access it using http://example.com/pic.png?q=1, http://example.com/pic.png?q=2, http://example.com/pic.png?q=3, and so on.
this way each rime you have diferent url, and browser will download image every time
So the browser will download a different image every time, but isn't the last/original image still being stored in your browser's cache??


Debbie
doubledee is offline   Reply With Quote
Old 10-07-2012, 08:32 PM   PM User | #6
patryk
Regular Coder

 
patryk's Avatar
 
Join Date: Oct 2012
Location: /dev/couch
Posts: 395
Thanks: 2
Thanked 64 Times in 64 Posts
patryk is on a distinguished road
If you'll use URL method, most browser will cache images and discard them when you leave page. That's true also for files with no-cache headers (browser need to have images to display them afterall).
Usually purpose of disabling caching is to display several dynapically generated images with the same url on one page and in that case both methods would work.

maybe i can give you more speciffic info if you'll tell why you want to prevent caching
patryk is offline   Reply With Quote
Old 10-07-2012, 09:45 PM   PM User | #7
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 640
Thanks: 20
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
Quote:
Originally Posted by patryk View Post
If you'll use URL method, most browser will cache images and discard them when you leave page. That's true also for files with no-cache headers (browser need to have images to display them afterall).
Usually purpose of disabling caching is to display several dynapically generated images with the same url on one page and in that case both methods would work.

maybe i can give you more specific info if you'll tell why you want to prevent caching
I am working on a project where teachers are writing Questions/Answers for a standardized test.

Each teacher logs into the Test Bank over a secure connection, writes their assigned Questions/Answers, it is reviewed and approved by a lead, and then the teacher can no longer view the Questions/Answers.

My client is worried that if a teacher is writing Test Questions/Answers at school or home, and things get cached in their browser or saved some other way (e.g. temp files on Op Sys), then there is an enormous risk that the Test could get into the wrong hands, which would be catastrophic!!!

(It is assumed that teachers are honest and will not save an Web Content or Images themselves.)

I know that you have to download a Web page and Web Images to view them, but is there a way to ensure that the minute a user navigate to a new page, or submits a form, or closes their browser that nothing is left behind in the Browser Cache or Temp Files??

Hope that helps,


Debbie
doubledee is offline   Reply With Quote
Old 10-07-2012, 10:44 PM   PM User | #8
patryk
Regular Coder

 
patryk's Avatar
 
Join Date: Oct 2012
Location: /dev/couch
Posts: 395
Thanks: 2
Thanked 64 Times in 64 Posts
patryk is on a distinguished road
In that case changing URLs won't help you at all i'm afraid.
As fare as I know your only option would be to include headers in all images, HTML documents and everything else you can download as teacher.
html:
Code:
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="pragma" content="no-cache">
or getter yet PHP:
Code:
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Pragma: no-cache');
There's of course autocompletion issue. you probably want to disable that as well

Last edited by patryk; 10-07-2012 at 11:06 PM.. Reason: wrong quoting in php code
patryk is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:09 AM.


Advertisement
Log in to turn off these ads.