Results 1 to 6 of 6

Thread: How to get production build using the same _dc invalidate cache for that build?

  1. #1
    Sencha Premium User SebTardif's Avatar
    Join Date
    Feb 2011
    Location
    Cambridge, MA
    Posts
    1,294

    Default How to get production build using the same _dc invalidate cache for that build?

    Sencha has the functionality to append _dc=xyz to almost everything with the goal to invalidate always the cache. The value change all the time, each time the application is loaded even if it's the same build, and nothing changed.

    Well, I would like production build to still append _dc but the value should be fixed/stable for that build. So mainly invalidating stale version of the application in my customer browsers.

    Is this a scenario already supported?

    If yes, what are the settings?

    If no, could we get an enhancement request open right away?

  2. #2
    Sencha - Engineering israelroldan's Avatar
    Join Date
    Nov 2011
    Location
    The Netherlands
    Posts
    395

    Default

    A quick way to do this would be to add the following targets to your build.xml file:
    Code:
        <target name="-before-init">
            <buildnumber file="build.num"/> <!-- this task generates a build.num file to track the builds -->
        </target>
    
    
        <target name="-after-page">
            <if>
                <resourcecontains resource="${build.dir}/index.html" substring="=+new Date:" />
                <then>
                    <!-- here we replace the appearance of +new Date (which is used as value for the cache buster with the build id -->
                    <replaceregexp file="${build.dir}/index.html" match="\+new\sDate" replace="${build.number}" />
                </then>
            </if>
        </target>
    After building, the value of _dc will be your build id instead of the current timestamp.

    This is just a quick suggestion and it may need to be adjusted to suit your needs, for example, to use a different approach to getting the value used as cache buster or to account for a non-embedded manifest (if that's your configuration).
    Israel Roldán | Senior Software Engineer (Framework tools)

  3. #3
    Sencha Premium User SebTardif's Avatar
    Join Date
    Feb 2011
    Location
    Cambridge, MA
    Posts
    1,294

    Default

    Thanks for the pointer. I will try.

  4. #4
    Ext JS Premium Member Greendrake's Avatar
    Join Date
    Jul 2008
    Location
    New Zealand
    Posts
    200

    Default

    Quote Originally Posted by israelroldan View Post
    A quick way to do this would be to add the following targets to your build.xml file
    I can confirm it works. What happens there is the replacement of the following red-highlighted piece of code found in bootstrap.js and eventually making its way to index.html in compressed format:
    Code:
    if(cache === false) {
        buster = +new Date();
    } else if(cache !== true) {
        buster = cache;
    }
    So basically the workaround is to replace that bit with your own build number does not matter where you actually take the number from and how you inject it in there.

    Still it would be nice to be able to do that in some framework-provided way rather than applying dirty hacks.
    Know the actual implications of using GPL-licensed client-side JavaScript.

  5. #5
    Sencha Premium Member EPV's Avatar
    Join Date
    Dec 2010
    Location
    Sweden
    Posts
    361

    Default

    I have asked the same question here:
    https://www.sencha.com/forum/showthr...-in-production

    Mitchell suggested to change app.json like this:
    Code:
    "loader": {
        "cache": "${build.timestamp}"
    }
    Though, this makes the files cache in dev-mode as well. I guess that the hack from israelroldan will work both in dev & prod. Strange that there's no out of the box solution for this.

    / E

  6. #6
    Sencha Premium Member
    Join Date
    Dec 2011
    Posts
    27

    Default

    There are build environment specific settings so you can specify the cache busting for just production like:

    Code:
        "production": {
            "loader": {
                "cache": "${build.timestamp}"
            }
        },
    That way in development env the _dc parameter is not added to modules loaded by the loader (still added to Ajax.requests etc. from the application), you can turn off caching in your dev browser (see numerous posts on how to do this) and breakpoints will still work.

Tags for this Thread

Posting Permissions

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