6 Replies Latest reply on Feb 18, 2016 10:07 AM by kglad

    Canvas: The wrath of cache

    ClayUUID Adobe Community Professional

      So in Animate, the old issue with previewed pages showing the previously cached content has been fixed. But a new caching issue has arisen in its place. Now, for me at least, author-loaded resources are getting inappropriately cached. I use the following code to load a script module in all my pages:

       

      var script = document.createElement("script");
      script.src = "justsomescript.js";
      document.head.appendChild(script);
      

       

      I realize there are many other ways to dynamically load scripts, including CreateJS's own script loader, but this pattern proved to be the most robust when it came to working in preview mode, from network drives, my local drive, etc.

       

      Anyway, this worked perfectly under Flash CC 2015. But now under Animate, any changes to the loaded script are NOT reflected when the page is run. Sometimes a Ctrl-F5 in the browser will take care of it, but other times I've had to remove the script file entirely, run the page, then put it back before it will load the current version.

       

      I've already filed a bug report (I think... there's currently no feedback that the report actually got submitted), but wanted to post about it here as well in case anyone else runs into this.

        • 1. Re: Canvas: The wrath of cache
          kglad Adobe Community Professional & MVP

          i always append version numbers.  then you just need to update the version variable:

           

          var version = 1;

          1. var script = document.createElement("script"); 
          2. script.src = "justsomescript.js?v="+version
          3. document.head.appendChild(script); 

           

          • 2. Re: Canvas: The wrath of cache
            dharmk Adobe Employee

            You can also try the following:

             

            var script = document.createElement("script");

            script.src = "justsomescript.js?" + (new Date()).getTime();

            document.head.appendChild(script);

            • 3. Re: Canvas: The wrath of cache
              ClayUUID Adobe Community Professional

              Thanks for the suggestion. That works, but I generally dislike cache-defeating measures for assets that rarely change. I'd essentially be making my own life easier at the expense of the end-user experience once all these pages hit production.

               

              I suppose I could tweak the generated query string so it only forces a refresh, like, every hour or so.

              • 4. Re: Canvas: The wrath of cache
                Colin Holgate MVP & Adobe Community Professional

                The version number idea might be better, in that you would only change that when you have made changes to the JS file.

                • 5. Re: Canvas: The wrath of cache
                  ClayUUID Adobe Community Professional

                  This is a support script used by hundreds of pages, so modifying them all every time the script is updated isn't a practical option. For now I'll try rolling out something like this:

                   

                  script.src = "test.js?" + Math.floor(new Date().getTime() / 3600000);

                   

                  Essentially expiring the script once an hour, on the hour.

                  • 6. Re: Canvas: The wrath of cache
                    kglad Adobe Community Professional & MVP

                    i use an anchor function that updates all the pages versions.  this is the jquery version:

                     

                    function anchorF(){

                        $('a').each(function(index){

                            if($(this).attr('href').indexOf('?v=')>-1){

                                var hrefA = $(this).attr('href').split('?v=');

                                $(this).attr('href',hrefA[0]+'?v='+version);

                            }

                        });

                    }

                    1 person found this helpful