Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,127
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Prevent Caching??

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


    Debbie

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    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

  • #4
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,127
    Thanks
    27
    Thanked 0 Times in 0 Posts
    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

  • #5
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,127
    Thanks
    27
    Thanked 0 Times in 0 Posts
    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

  • #6
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    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

  • #7
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,127
    Thanks
    27
    Thanked 0 Times in 0 Posts
    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

  • #8
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    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-08-2012 at 12:06 AM. Reason: wrong quoting in php code


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •