Advanced Search

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Clear Browser Cache with Javascript?

  1. #1
    Join Date
    Nov 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Clear Browser Cache with Javascript?

    Hi
    I'm looking for a script that can clear browser cache at page load.
    Or is it possible to clear cache only of images?

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    You can't. The End.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  3. #3
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,486
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Well.... I wouldn't say the end. it is possible on some degree, but very intrusive and I haven't yet seen a method that works correctly.

    You certainly cannot do it with an SSI language or a script. And certainly not without the users knowledge (read: permission).

    Perhaps though, we need more information from the O.P. as to a why, perhaps there is something s/he wants done that can be accomplished without clearing cache. Perhaps.
    {CWoT - Riddle } {OSTU - Psycho} {Invasion - Team}
    Follow Me on Twitter: @Negative_Chaos
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,156
    Thanks
    262
    Thanked 690 Times in 678 Posts

    Default

    Security issue and completely impossible, but it might be possible to solve the problem another way, or attach a no-cache header for a page that must reload each time, etc. Once it is on the computer, though, nothing can be done, at all, short of invading the computer with ActiveX or a Java applet, at which point you could just as easily rename their C drive as delete their cache.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Nov 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hmm.. Here's my problem. We update news on our website with own CMS System. Each time the news are updated, images of old news are left in browser cache so viewers need to refresh the browser 2 to 3 times (several sometimes) to get the correct images.

  6. #6
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,486
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Couple things.

    In the <head> section add meta tag:

    Code:
    <meta http-equiv="pragma" content="no-cache" />
    Basically the browser won't cache the page.

    Another option is to set sessions, this will force the browser to a new session each time they go, and thus make the browser get the page from the server instead of the cache

    PHP Code:
    <?php
    session_start
    ();

    $_SESSION = array();
    session_destroy();

    ?>
    {CWoT - Riddle } {OSTU - Psycho} {Invasion - Team}
    Follow Me on Twitter: @Negative_Chaos
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  7. #7
    Join Date
    Nov 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'll try the first one. Can't try second as my page is written with asp.net

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,156
    Thanks
    262
    Thanked 690 Times in 678 Posts

    Default

    You could also add a random variable to the end of the image:
    <img src="image.jpg?state=[random]">
    like state=29422488713, then it will think it's a new image each time, and reload it.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,704
    Thanks
    43
    Thanked 3,133 Times in 3,097 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by rapster88 View Post
    I'll try the first one. Can't try second as my page is written with asp.net
    asp.net must have an equivalent to tell the browser not to cache the page, consult the documentation.

    Quote Originally Posted by djr33 View Post
    You could also add a random variable to the end of the image:
    <img src="image.jpg?state=[random]">
    like state=29422488713, then it will think it's a new image each time, and reload it.
    Random numbers may repeat, it's better to add a number generated from the Date object.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    Jun 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i created an account here only so i could share my dissapointment with this community.


    real programmers know nothing is impossible, but rather different approaches may be preferred because they're easier.

    this thinking of, 'it isn't possible' is completly ridiculas. i could tell you how it would be possible myself.


    the biggest problem: finding out how to compile assembly language inside of javascript. even if you have to dynamically create a text-file, save it as .cpp, and compile it with a mini-compiler; it's possible.

    once you have it in assembly.... it's easy. there's not really any such thing as 'security' in the __asm language.


    go ahead, argue with me that what's described above is 'impossible'


    i'll post my code when i have a javascript cookie clearer, if i feel you guys are worthy <3

Bookmarks

Posting Permissions

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