Google analytics code

Monday, July 8, 2013

Sencha Touch: Disable script caching

While working on a Sencha Touch project I needed to look in one of the core sencha files. The problem is there is a _dc property attached to every script it brings in. It's great for making sure your code isn't cached, but terrible for debugging.

After a big of digging I found the code needed to turn off caching. Open up the app.js file and look at the very top. You should see a Ext.Loader.setPath method. Update it to look like this and caching should now be disabled.

Ext.Loader.setPath({
    'Ext': 'touch/src',
    'Sample': 'app'
}).setConfig({
    disableCaching: false
});

5 comments:

  1. Um, don't you mean setting disableCaching to false will ENABLE caching? When disableCaching is true...well, it disables caching.

    ReplyDelete
  2. It's a really confusing property. Some of the comments on the property on the sencha docs site said it's named pretty poorly.

    When disableCaching is set to true it still adds the _dc property to all the loaded scripts. When it's set to false the _dc is gone and it no longer caches the script.

    It's weird which is why I posted about it.

    You can see what I mean by turning on the dev tools in Chrome (osx: cmd+alt+i / win: ctrl+alt+i) and goto the sources tab. Press (osx: cmd+o / win: ctrl+o) and type Bar.js. When disableCaching is false there is no _dc. When it's true you see the _dc property.

    ReplyDelete
  3. You have it backwards. The _dc parameter is added to the URL so that it is unique and therefore not cached. When the _dc parameter is not present, only then will it be cached as the URL will always be the same.

    ReplyDelete
    Replies
    1. Thanks for catching that. I'll update the post.

      Delete
  4. Thanks for this. I was thinking it was Ext.Ajax.

    ReplyDelete

If you found this page useful, or you have any feedback, please leave a comment.