Cache Prevention for Dojo xhr requests

/**
 * Cache Prevention for Dojo xhr requests
 *
 * Adds no-cache header and enables dojo's preventCache feature
 * for every dojo xhr call. This prevents the caching of partial
 * refreshs.
 *
 * @author Sven Hasselbach
 * @version 0.3
 *
 **/
dojo.addOnLoad(
    function(){
        if( !dojo._xhr )
        dojo._xhr = dojo.xhr;
        
        dojo.xhr = function(){        
            try{
                var args = arguments[1];   
                args["preventCache"] = true;
                args["headers"] = { "cache-control": "no-cache" };
                arguments[1] = args;
        	}catch(e){}
        	
        	dojo._xhr( arguments[0], arguments[1], arguments[2] );
        }
    }
)





This small snippet prevents caching of all Dojo's xhr request (which includes Partial Refreshs)
Just add it the code to a <xp:scriptBlock> on your XPage.

See here for more details:
http://julianbuss.com/blog/a-big-issue-for-mobile-web-apps-with-xpages-for-iphone-and-ipad-and-how-to-solve-it-htm/

JavaScript (Client)
Sven Hasselbach
January 23, 2013 5:33 AM
Rating
118

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



1 comment(s)Login first to comment...
Panu Haaramo
(at 05:28 on 28.01.2013)
Using this breaks the DataGrid: http://stackoverflow.com/questions/14519695/disable-cache-in-extlib-rest-control-which-uses-dojox-data-jsonreststore