A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Need to clear browers cache automatically for my site

  1. #1
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971

    Need to clear browers cache automatically for my site

    I need to clear the browsers cache for my site automatically with java or html or php. That's because I will add new levels on my flash game swf , and the people won't see the changes because they will have the old or cached swf on their systems, and I don't want complaints. I read something on google but I didn't understand well. Maybe someone can shed some light on me? Hehe


    Or maybe disabling cache for my site at all? Thanks

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    you can try this

    PHP Code:
    <?php 
    function clearBrowserCache() {
        
    header("Pragma: no-cache");
        
    header("Cache: no-cache");
        
    header("Cache-Control: no-cache, must-revalidate");
        
    header("Expires: Mon, 9 Jul 1995 05:00:00 GMT");
    }
    clearBrowserCache();
    ?>

  3. #3
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Do i put that on my site's html, or do i have to create the .php apart and call it from the html? Thanks

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    you would need to call your page .php to use the php code

    you can always use html code

    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="no-cache">
    <meta http-equiv="Expires" content="-1">
    <meta http-equiv="Cache-Control" content="no-cache">

  5. #5
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Perfect. I will try that. Thanks. I'm new with all this of progamming languages. I started with basic html, then actionscript 2, and now i'm begining with python, html5, java etc...

  6. #6
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    in case it does not work (you are telling the browser to reload the html/php part, not the flash part), there are three options
    a) modify name of your swf - perhaps add some ?version=47 to the url
    b) check whether your host runs apache and supports mod_expires
    c) deliver the swf file via php and send some no-cache headers

    Musicman

  7. #7
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Oh! Thanks for the feedback hehe!

    For the moment, I have my game/site hosted in my own computer, in Windows IIS Server 7 so i dont know if It supports mod_expires...but I think I can configure it so it supports it, i reed something about "scripts" in the options of IIS.

    Anyway, i will try HTML method first
    PHP Code:
    <meta http-equiv="Pragma" content="no-cache">
    <
    meta http-equiv="no-cache">
    <
    meta http-equiv="Expires" content="-1">
    <
    meta http-equiv="Cache-Control" content="no-cache"
    If that does't work, the php then

    PHP Code:
    <?php
    function clearBrowserCache() {
        
    header("Pragma: no-cache");
        
    header("Cache: no-cache");
        
    header("Cache-Control: no-cache, must-revalidate");
        
    header("Expires: Mon, 9 Jul 1995 05:00:00 GMT");
    }
    clearBrowserCache();
    ?>
    And name my site index.php

    Hope this works. The browser's cache is apart of the flash's sharedobjects, right? Because I want the shared objects (.sol) to be cache. They holds the "Saved" levels of the game and other variables. The only thing i dont want to cache is the .swf flash movie itself, because I constantly overwrite the SWF with new levels. Thanks

  8. #8
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    for the swf you might want to have your load command looking something similar to this.
    Actionscript Code:
    loadMovie("myFile.swf?val="+random(99999), myLoadArea);

    you can't always be sure that people have flash settings enabled for local storage, I do turn it off now and then.

  9. #9
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Most people, don't even know they can configure flash settings hehe...

    May you explain me what does that script do? I tried to understand it buy i don't get a clue...

  10. #10
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    It will basically always load the newest flash movie each time.

    and the flash settings, right click a flash movie, click settings (not global settings) if it is clickable (it wont be clickable if a movie has no AS or very low key AS) then select the folder icon (local storage) set the amount to whatever it allows/ or none for off essentially.

  11. #11
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Yes I know about the local storage...but it only takes effects on my computer, so users would have to do the same in order to have always the updated swf, and don't "store" the files. But anyway i don't want the users/players to delete the Shared objects (.sol) caching, because as i said, they hold the last played level variables.

    Now I understand the random function, I will apply it to my loaded swf. Thank you very much fruitbeard!

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center