使用dojo后一直纠结js文件内容有更新时如何加载,这两天终于把问题解决了,原来想加一个库文件代替dojo相应的函数,但发现dojo库纠緾得太紧了,就在原文件上改。
加载分两种情况一种dojo.text!加载或不用执行代码,另外一个是作为库加载,这两个要分开处理。
第一种是直接在加载的url后面加入版本号“?v=xxx"。
toUrl = req.toUrl = function(name, referenceModule){ var moduleInfo = getModuleInfo(name+"/x", referenceModule), url= moduleInfo.url; url=url.substring(0, url.length-5) if (req.version){ url += "?"+req.version; name+="?"+req.version; } return fixupUrl(moduleInfo.pid===0 ? // if pid===0, then name had a protocol or absolute path; either way, toUrl is the identify function in such cases name : // "/x.js" since getModuleInfo automatically appends ".js" and we appended "/x" to make name look like a module id url//url.substring(0, url.length-5) );
compactPath = function(path){ var p=path; var result = [], segment, lastSegment; path = path.replace(/\\/g, '/').split('/'); while(path.length){ segment = path.shift(); if(segment==".." && result.length && lastSegment!=".."){ result.pop(); lastSegment = result[result.length - 1]; }else if(segment!="."){ result.push(lastSegment= segment); } // else ignore "." } var url=result.join("/"); if(p.indexOf('/x.js')==-1 && req.version && p.indexOf('.js')!=-1){ url+="?"+req.version; //console.log('compactPath result:',path,result); } return url; },
使用时在require库增加version属性即可。
require.version=‘v0.1‘;
原文地址:http://blog.csdn.net/moxien/article/details/38554489