dojo實現載入新版本js庫

來源:互聯網
上載者:User

標籤:dojo   js   

使用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 casesname :// "/x.js" since getModuleInfo automatically appends ".js" and we appended "/x" to make name look like a module idurl//url.substring(0, url.length-5));

另外一種是在載入庫檔案時添加版本號碼“?v=xxx"。

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‘;


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.