litesoft
@ HEAD
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
<!DOCTYPE HTML> <html><head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>What's with all the cache/nocache stuff and weird filenames?</title> <script type="text/javascript"><!-- (function(){function a(){this.t={};this.tick=function(c){this.t[c]=(new Date).getTime()};this.tick("start")}var b=new a;window.jstiming={Timer:a,load:b};if(window.external&&window.external.pageT)window.jstiming.pt=window.external.pageT;})(); var _tocPath_ = '/webtoolkit/_doc_toc.ezt'; var codesite_token = null; var logged_in_user_email = null; //--></script> <link href="GWTdev_files/codesite.css" type="text/css" rel="stylesheet"> <script src="GWTdev_files/codesite_head.js" type="text/javascript"></script> <script type="text/javascript">CODESITE_CSITimer['load'].tick('bhs');</script> <link rel="search" type="application/opensearchdescription+xml" title="Google Code" href="http://code.google.com/osd.xml"> <!--[if IE]><link rel="stylesheet" type="text/css" href="/css/iehacks.css"><![endif]--> <link href="GWTdev_files/semantic_headers.css" rel="stylesheet" type="text/css"> <link rel="stylesheet" href="GWTdev_files/local_extensions.css" type="text/css"> <script src="GWTdev_files/ga.js" async="" type="text/javascript"></script><script src="GWTdev_files/googleapis.js"></script></head><body class="gc-documentation"> <script type="text/javascript"> var _gaq = _gaq || []; var cookiePath = '/webtoolkit/'; if (cookiePath.lastIndexOf('.html') > cookiePath.lastIndexOf('/')) { cookiePath = cookiePath.substring(0, cookiePath.lastIndexOf('/') + 1); }; _gaq.push( ['projectTracker._setAccount', 'UA-18071-28'], ['projectTracker._setDomainName', 'code.google.com'], ['projectTracker._setCookiePath', cookiePath], ['projectTracker._trackPageview'], ['siteTracker._setAccount', 'UA-18071-1'], ['siteTracker._setDomainName', 'code.google.com'], ['siteTracker._setCookiePath', cookiePath], ['siteTracker._trackPageview'] ); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga); })(); </script> <h2 id="What's_with_all_the_cache/nocache_stuff_and_weird_filenames">What's with all the cache/nocache stuff and weird filenames?</h2> <p>During its bootstrap process, a Google Web Toolkit application goes through a series of sometimes cryptically-named files. These files, generated by the GWT Compiler, usually seem strange to developers new to GWT. To effectively deploy a GWT application, however, it is necessary to understand these files so that they can be placed appropriately on the web server.</p> <p>The important files produced by the GWT Compiler are:</p> <ul> <li> <i><Module Name></i><tt>.nocache.js</tt> </li> <li> <i><alphanumeric></i><tt>.gwt.rpc</tt> </li></ul> <p>Each of the items listed above is described below. However, first it's important to understand the concept of deferred binding since that notion is at the heart of the bootstrap process injected into the <tt><Module Name>.nocache.js</tt> file, so you might want to read a bit about <a href="http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasics.html#DevGuideDeferredBinding">deferred binding</a> before continuing.</p> <p>Before explaining what each file does, it's also useful to summarize the overall bootstrap procedure for a GWT application:</p> <ol> <li>The browser loads and processes the host HTML page.</li> <li>When the browser encounters the page's <tt><script src="<Module Name>.nocache.js"></tt> tag, it immediately downloads and executes the JavaScript code in the file.</li> <li>The <tt>.nocache.js</tt> file contains JavaScript code that resolves the Deferred Binding configurations (such as browser detection, for instance) and then uses a lookup table generated by the GWT Compiler to locate one of the <tt>.cache.html</tt> files to use.</li> <li>The JavaScript code in <tt>.nocache.js</tt> then creates a hidden <tt><iframe></tt>, inserts it to the host page's DOM, and loads the <tt>.cache.html</tt> file into that iframe.</li> <li>The <tt>.cache.html</tt> file contains the actual program logic of the GWT application.</li> </ol> <p>That's the process in a nutshell. For an example the bootstrap process for a complete GWT application, check out the <a href="http://code.google.com/webtoolkit/doc/latest/DevGuideOrganizingProjects.html#DevGuideBootstrap">Developer Guide example</a>. The sections below describe each of the GWT application files in detail.</p> <h5 id="The_.cache.html_Files">The .cache.html Files</h5> <p>The "cache" files contain your application's logic. If you were to look inside a <tt>.cache.html</tt> file, you would see that it is JavaScript code wrapped in a thin HTML wrapper. You might wonder why the GWT Compiler doesn't simply emit it as a JavaScript .js file. The reason for this is that certain browsers do not correctly handle compression of pure-JavaScript files in some circumstances. This would effectively mean that users unfortunate enough to be using such a browser would download the .js file uncompressed. Since the GWT mantra is no-compromise, high-performance AJAX code, the GWT Compiler wraps the JavaScript in an HTML file to wiggle around this browser quirk.</p> <p>They are named according to the MD5 sum of their contents. This guarantees deterministic behavior by the GWT Compiler: if you recompile your application without changing code, the contents of the output will not change, and so the MD5 sums will remain the same. Conversely, if you do change your source code, the output JavaScript code will likewise change, and so the MD5 sums and thus the filenames will change.</p> <p>Because of this uniqueness guarantee, it is safe (and indeed preferable) for browsers to cache these files, which is reflected in their <tt>.cache.html</tt> file extension.</p> <h5 id="The_.nocache.js_File">The .nocache.js File</h5> <p>The "nocache" file is where <a href="http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasics.html#DevGuideDeferredBinding">Deferred Binding</a> occurs. Before the application can run, any dynamically-bound code must be resolved. This might include browser-specific versions of classes, the specific set of string constants appropriate to the user's selected language, and so on. In Java, this would be handled by simply loading an appropriate service-provider class that implements a particular interface. To maximize performance and minimize download size, however, GWT does this selection up-front in the "nocache" file.</p> <p>The reason the file is named ".nocache.html" is to indicate that the file should never be cached. That is, it must be downloaded and executed again each time the browser starts the GWT application. The reason it must be re-downloaded each time is that the GWT Compiler regenerates it each time, but under the same file name. If the browsers were allowed to cache the file, they might not download the new version of the file, when the GWT application was recompiled and redeployed on the server. To help prevent caching, the code in <tt>gwt.js</tt> actually appends an HTTP GET parameter on the end of file name containing a unique timestamp. The browser interprets this as a dynamic HTTP request, and thus should not load the file from cache.</p> <h4 id="Summary">Summary</h4> <p>That is the story behind the somewhat strange GWT file names. The <tt><module>.nocache.js</tt> performs the deferred binding resolution and selects a cache file based on the execution context </p><p> </body></html> |