Prevent cache in every Dojo xhr request on page

后端 未结 2 736
轻奢々
轻奢々 2021-01-26 05:30

I\'m able to intercept Dojo 1.6.1 xhr requests using IO Pipeline Topics as described here:

Dojo - intercepting XHR calls

I would like to add a time para

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-26 06:09

    The answer comes once again from Sven Hasselbach:

    /**
     * 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] );
            }
        }
    )
    

    http://openntf.org/XSnippets.nsf/snippet.xsp?id=cache-prevention-for-dojo-xhr-requests

    Tried it out and it does exactly what I was looking for by adding &dojo.preventCache=1359366392301 parameter to the xhr URLs. And it seems to add a cache-control header too.

提交回复
热议问题