3 Replies Latest reply on Apr 25, 2006 12:08 PM by Newsgroup_User

    Need to clear cache to see dynamic changes?

    Leo_D.
      I have a Flash site/movie that loads several JPG's via button.

      I'm using loadMovie.

      Client is saying that he has to clear his cache to see chaqnges when replacing or updating these images.

      Same is happening on some dynamivc text files.

      I should know this by now but....

      Why and can I avoid this?

      Thanks in adavance. Client is asking.
        • 1. Re: Need to clear cache to see dynamic changes?
          Level 7
          Leo,

          > I have a Flash site/movie that loads several JPG's
          > via button.
          >
          > Client is saying that he has to clear his cache to see
          > chaqnges when replacing or updating these images.

          Yup, this happens. :-/

          > I should know this by now but....
          >
          > Why and can I avoid this?

          The theory behind cacheing is actually a good thing. After all, why
          waste network traffic if the user already has the file, right? The trouble
          is, browsers don't always seem able to know when a file is new. It may be
          due to the slight differences in your clock and your client's clock,
          especially if you're uploading and checking these in a very quick
          turnaround.

          The solution is to "trick" your browser into thinking it's requesting a
          new file. One way to do this is to append a query string to the end of your
          requests for external files.

          In the loadMovie() parameter that specifies the URL, do something like
          this ...

          "blah/blah/sample.jpg?ver=001"

          ... which essentially appends a fake variable, ver (for version), to your
          request. When you make a change, update that 001 to a 002, and so on.
          Pretty slick. I would also do this in the HTML that actually embeds the
          SWF.

          "blah/blah/sample.swf?ver=001"

          ... in both the object and embed tags.

          If you really want to get fancy, use the Math.random() method to
          generate a new number every time. In your ActionScript ...

          "blah/blah/sample.jpg?ver=" + Math.random()

          ... but remember, that means your client will re-download this file *every
          time*. That may be what you want during testing, but it's almost certainly
          not what you want when the project is complete -- so don't forget to remove
          this trick later.


          David
          stiller (at) quip (dot) net
          Dev essays: http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: Need to clear cache to see dynamic changes?
            Leo_D. Level 1
            i think i can handled adding the query string at the end of the file requests.

            when you say:

            ... which essentially appends a fake variable, ver (for version), to your
            request. When you make a change, update that 001 to a 002, and so on.
            Pretty slick. I would also do this in the HTML that actually embeds the
            SWF.

            Do you mean every time the client switches the files out, i need to update the script in the string?
            • 3. Re: Need to clear cache to see dynamic changes?
              Level 7
              Leo,

              > Do you mean every time the client switches the files out, i
              > need to update the script in the string?

              No. I didnt' realize the files were being supplied by the client. But
              that's okay. I suppose, in a case like this, you might just want to use
              the Math.random() method to supply a new number for you every time. There
              are pros and cons to everything. The pro here is that the JPGs will always
              be loaded as if new -- even if they aren't. The con here is that the JPGs
              will always be loaded as if new -- even if they aren't.


              David
              stiller (at) quip (dot) net
              Dev essays: http://www.quip.net/blog/
              "Luck is the residue of good design."