Show
Ignore:
Timestamp:
02/25/07 22:46:42 (23 months ago)
Author:
jburke
Message:

References #2366. Have something primitive working for the build cache. Still need to do more testing, and something is weird with compression -- failure in makeDojoJsWeb.js when trying to make it.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/0.4/buildscripts/webbuild/index.html

    r7448 r7450  
    113113        dojo.require("dojo.widget.TreeEmphasizeOnSelect"); 
    114114        dojo.require("dojo.html.iframe"); 
     115        dojo.require("dojo.crypto.MD5"); 
     116        dojo.require("dojo.string.extras"); 
    115117 
    116118        //assign output node on load. 
     
    124126        } 
    125127         
     128        function getCachedBuildUrl(depList){ 
     129                var doCompression = document.masterForm.doCompression[1].checked ? true : false; 
     130                var sortedFileList = depList.sort().join(","); 
     131                var buildKey = dojo.crypto.MD5.compute(sortedFileList, dojo.crypto.outputTypes.Hex); 
     132                return "dojobuilds/" + buildKey + (doCompression ? "/compressed" : "") + "/dojo.js"; 
     133        } 
     134 
    126135        function sendDependencyResultToServer(dependencyResult){ 
    127136                clearOutput(); 
    128137 
     138                //Find out if the build result is already on the server. 
     139                var cachedBuildUrl = getCachedBuildUrl(dependencyResult.depList); 
     140                dojo.io.bind({ 
     141                        //Add an URL marker for the server to know if this is an existence query. 
     142                        //Mostly helpful in the Safari 2.0 case where it doesn't support HEAD 
     143                        //requests. This marker should be used to filter server logs when trying to find 
     144                        //download counts. 
     145                        url: cachedBuildUrl + "?query=exist", 
     146                        method: "HEAD", 
     147                        mimetype: "text/plain", 
     148                        handle: function(type, data, xhr, kwArgs){ 
     149                                var httpStatus = parseInt(xhr.status, 10); 
     150                                if(httpStatus >= 400){ 
     151                                        //Build does not exist. Ask server to make it. 
     152                                        requestServerBuild(dependencyResult); 
     153                                }else{ 
     154                                        outputBuildResults(dependencyResult); 
     155                                        window.location = "../" + cachedBuildUrl; 
     156                                } 
     157                        } 
     158                }); 
     159        } 
     160 
     161        function requestServerBuild(dependencyResult){ 
    129162                var depListForm = document.depListForm; 
    130                 depListForm.action = "../webbuild.php"; 
    131                 depListForm.depList.value = dependencyResult.depList.join(","); 
    132                 depListForm.provideList.value = dependencyResult.provideList && dependencyResult.provideList.length > 0 ? dependencyResult.provideList.join(",") : "null"; 
    133                 depListForm.version.value = version; 
    134                 depListForm.xdDojoUrl.value = xdDojoUrl; 
    135                 depListForm.doCompression.value = document.masterForm.doCompression[1].checked ? true : false; 
    136  
     163                 
     164                //Ask the server to build the result. 
     165                dojo.io.bind({ 
     166                        url: "../webbuild.php", 
     167                        method: "POST", 
     168                        mimetype: "text/plain", 
     169                        content: { 
     170                                depList: dependencyResult.depList.join(","), 
     171                                provideList: (dependencyResult.provideList && dependencyResult.provideList.length > 0) ? dependencyResult.provideList.join(",") : "null", 
     172                                version: version, 
     173                                xdDojoUrl: xdDojoUrl 
     174                        }, 
     175                        handle: function(type, data, xhr, kwArgs){ 
     176                                if(type == "load" && dojo.string.trim(data).indexOf("OK") == 0){ 
     177                                        outputBuildResults(dependencyResult); 
     178                                        window.location = "../" + getCachedBuildUrl(dependencyResult.depList); 
     179                                }else{ 
     180                                        alert("Build " + type + " [" + data + "]"); 
     181                                } 
     182                        } 
     183                }); 
     184 
     185        } 
     186 
     187        function outputBuildResults(dependencyResult){ 
    137188                //reset the hidden frame so we can do another build. 
    138189                setTimeout(function(){ 
     
    155206                        } 
    156207                } 
    157  
    158                 //Submit form to generate custom dojo.js file. 
    159                 depListForm.submit(); 
    160208        } 
    161209