1 |
|
2 | /* litejs.com/MIT-LICENSE.txt */
|
3 |
|
4 |
|
5 |
|
6 | // With initial congestion window set to 2 and 1452 bytes of data in a segment.
|
7 | //
|
8 | // 1 round trip to get 2904 bytes, Initial Window (IW) = 2
|
9 | // 2 round trips to get 8712 bytes, Congestion Window (CW)=4
|
10 | // 3 round trips to get 20328 bytes, CW = 8
|
11 | // 4 round trips to get 43560 bytes, CW = 16
|
12 |
|
13 |
|
14 | // Scripts that are dynamically created and added to the document are async by default
|
15 | // HTML5 declared that browsers shouldn’t download scripts with an unrecognised type
|
16 |
|
17 |
|
18 | // IE9 and below allows up to 32 stylesheets, this was increased to 4095 in IE10.
|
19 |
|
20 | // You can invalidate a URL in the browser's cache by sending a PUT method xmlhttprequest to it:
|
21 | // xhr("PUT", url).send(null) Works in all major browsers
|
22 |
|
23 | // XMLHttpRequest was unsupported in IE 5-6 and PATCH is not supported in IE7-8.
|
24 | // IE does not allow to add arbitrary properties to ActiveX objects.
|
25 | // IE does not allow to assign or read the readystatechange after the send().
|
26 | // Last version-independent ProgID with 3.0 is good enough (MSXML2 is supported from IE4.01).
|
27 | // MSXML 6.0 has improved XSD, deprecated several legacy features
|
28 | // What's New in MSXML 6.0: https://msdn.microsoft.com/en-us/library/ms753751.aspx
|
29 |
|
30 | !function(window, scripts, next) {
|
31 | var seq = 0
|
32 | , xhrs = []
|
33 | , loaded = {}
|
34 | , urlEscRe = /[+#\s]+/g
|
35 | , XMLHttpRequest = +"\v1" && window.XMLHttpRequest || Function("return new ActiveXObject('MSXML2.XMLHTTP')")
|
36 | , execScript = window.execScript ||
|
37 | // THANKS: Juriy Zaytsev - Global eval [http://perfectionkills.com/global-eval-what-are-the-options/]
|
38 | Function("d,Date", "return(1,eval)('(Date)')==d&&eval")(Date, 1) ||
|
39 | Function("a", "var d=document,b=d.body,s=d.createElement('script');s.text=a;b.removeChild(b.insertBefore(c,b.firstChild))")
|
40 |
|
41 | /*** errorLog ***/
|
42 | , lastError
|
43 | , unsentErrors = []
|
44 |
|
45 | window.onerror = onerror
|
46 | function onerror(message, file, line, col, error) {
|
47 | // Do not send multiple copies of the same error.
|
48 | if (lastError !== (lastError =
|
49 | [ file
|
50 | , line
|
51 | , col || (window.event || unsentErrors).errorCharacter || "?"
|
52 | , message
|
53 | ].join(":")
|
54 | ) && 1 == unsentErrors.push(
|
55 | [ lastError
|
56 | , error && (error.stack || error.backtrace || error.stacktrace) || "-"
|
57 | , +new Date()
|
58 | , "" + location
|
59 | ]
|
60 | )) setTimeout(sendErrors, 307)
|
61 | }
|
62 |
|
63 | function sendErrors() {
|
64 | if (xhr.logErrors) {
|
65 | xhr.logErrors(unsentErrors)
|
66 | } else {
|
67 | setTimeout(sendErrors, 1307)
|
68 | }
|
69 | }
|
70 | /**/
|
71 |
|
72 | // next === true is for sync call
|
73 | //
|
74 | // Hypertext Transfer Protocol (HTTP) Status Code Registry
|
75 | // http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
|
76 | //
|
77 |
|
78 | window.xhr = xhr
|
79 | function xhr(method, url, next, attr1, attr2) {
|
80 | // encodeURI("A + B").replace(/%5[BD]/g, decodeURI).replace(/\+/g, "%2B").replace(/%20/g, "+")
|
81 | // unescape("A+%2B+B".replace(/\+/g, " "))
|
82 | var xhr = xhrs.shift() || new XMLHttpRequest()
|
83 |
|
84 | // To be able to reuse the XHR object properly,
|
85 | // use the open method first and set onreadystatechange later.
|
86 | // This happens because IE resets the object implicitly
|
87 | // in the open method if the status is 'completed'.
|
88 | // MSXML 6.0 fixed that
|
89 | //
|
90 | // The downside to calling the open method after setting the callback
|
91 | // is a loss of cross-browser support for readystates.
|
92 | // http://www.quirksmode.org/blog/archives/2005/09/xmlhttp_notes_r_2.html
|
93 |
|
94 |
|
95 | // function progress(ev) {
|
96 | // if (ev.lengthComputable) {
|
97 | // var percentComplete = (ev.loaded / ev.total) * 100
|
98 | // }
|
99 | // }
|
100 | // xhr.upload.addEventListener("progress", onProgressHandler)
|
101 | // xhr.addEventListener("progress", onProgressHandler)
|
102 | // xhr.onprogress = progress
|
103 |
|
104 |
|
105 | // Vodafone 360 doesn't pass session cookies, so they need to be passed manually
|
106 | // if (sessionID) xhr.setRequestHeader("Cookie", sessionID);
|
107 | // if (xhr.getResponseHeader("Set-Cookie")) sessionID = xhr.getResponseHeader("Set-Cookie");
|
108 |
|
109 |
|
110 | xhr.open(method, url.replace(urlEscRe, encodeURIComponent).replace(/%20/g, "+"), next !== true)
|
111 |
|
112 |
|
113 | // With IE 8 XMLHttpRequest gains the timeout property.
|
114 | // With the timeout property, Web developers can specify
|
115 | // the length of time in milliseconds for the host to wait for a response
|
116 | // before timing out the connection.
|
117 |
|
118 | //xhr.timeout = 10000
|
119 | //xhr.ontimeout = timeoutRaised
|
120 |
|
121 | if (next !== true) xhr.onreadystatechange = function() {
|
122 | if (xhr.readyState == 4) {
|
123 | // From the XMLHttpRequest spec:
|
124 | //
|
125 | // > For 304 Not Modified responses
|
126 | // > that are a result of a user agent generated conditional request
|
127 | // > the user agent must act as if the server gave a 200 OK response
|
128 | // > with the appropriate content.
|
129 | //
|
130 | // In other words, the browser will always give status code 200 OK,
|
131 | // even for requests that hit the browser cache.
|
132 | //
|
133 | // However, the spec also says:
|
134 | //
|
135 | // > The user agent must allow author request headers
|
136 | // > to override automatic cache validation
|
137 | // > (e.g. If-None-Match or If-Modified-Since),
|
138 | // > in which case 304 Not Modified responses must be passed through.
|
139 | //
|
140 | // So, there is a workaround to make the 304 Not Modified responses visible
|
141 | // to your JavaScript code.
|
142 | //
|
143 | // - Opera 8.x passes 304
|
144 | // - IE9 returns 1223 and drop all response headers from PUT/POST
|
145 | // when it should be 204,
|
146 | // http://www.enhanceie.com/ie/bugs.asp
|
147 | // - File protocol and Appcache returns status code 0
|
148 | // - Android 4.1 returns status code 0 when cache manifest is used
|
149 | // - IE 10-11 returns status code 0 with CORS for codes 401, 403
|
150 | // Fix: Internet options -> Trusted sites -> Custom Level ->
|
151 | // Miscellaneous -> Access data sources across domains -> Enable
|
152 | // - Use CloudFlare status "522 Connection Timed Out" for network error
|
153 |
|
154 | method = xhr.status || (xhr.responseText ? 200 : 522) // Reuse variable for status
|
155 | if (next) next.call(
|
156 | xhr,
|
157 | (method < 200 || method > 299 && method != 304 && method != 1223) && method,
|
158 | xhr.responseText,
|
159 | url,
|
160 | attr1,
|
161 | attr2
|
162 | )
|
163 | xhr.onreadystatechange = next = nop
|
164 | xhrs.push(xhr)
|
165 | }
|
166 | }
|
167 | return xhr
|
168 | }
|
169 |
|
170 |
|
171 | /*** require ***/
|
172 | var modules = {}
|
173 | , process = window.process = {
|
174 | env: {}
|
175 | }
|
176 |
|
177 | //process.memoryUsage = function() {
|
178 | // return (window.performance || {}).memory || {}
|
179 | //}
|
180 |
|
181 | window.require = require
|
182 | function require(name) {
|
183 | var mod = modules[name]
|
184 | if (!mod) throw Error("Module not found: " + name)
|
185 | if (typeof mod == "string") {
|
186 | var exports = modules[name] = {}
|
187 | , module = { id: name, filename: name, exports: exports }
|
188 | Function("exports,require,module,process,global", mod).call(
|
189 | exports, exports, require, module, process, window
|
190 | )
|
191 | mod = modules[name] = module.exports
|
192 | }
|
193 | return mod
|
194 | }
|
195 |
|
196 | require.def = function(map, key) {
|
197 | for (key in map) modules[key] = map[key]
|
198 | }
|
199 | /**/
|
200 |
|
201 | /**
|
202 | * 1. FireFox 3.0 and below throws on `xhr.send()` without arguments.
|
203 | * You can work around this by explicitly setting the message body to null.
|
204 | */
|
205 |
|
206 | xhr.load = load
|
207 | function load(files, next, raw) {
|
208 | if (typeof files == "string") files = [files]
|
209 | var file
|
210 | , len = files && files.length
|
211 | , i = 0
|
212 | , pending = 0
|
213 | , res = []
|
214 |
|
215 | for (; i < len; i++) if ((file = files[i]) && file !== loaded[file]) {
|
216 | if (loaded[file]) {
|
217 | !function(old, i2) {
|
218 | loaded[file] = function(err, str, file, i) {
|
219 | old(err, str, file, i)
|
220 | cb(1, str, file, i2)
|
221 | }
|
222 | }(loaded[file], i)
|
223 | } else {
|
224 | loaded[file] = cb
|
225 | xhr("GET", file, function(err, str, file, i) {
|
226 | loaded[file](err, str, file, i)
|
227 | }, pending).send(null) /* 1 */
|
228 | }
|
229 | pending += 1
|
230 | }
|
231 |
|
232 | if (!pending && next) next()
|
233 |
|
234 | function cb(err, str, file, i) {
|
235 | loaded[file] = file
|
236 | if (err) {
|
237 | res[i] = ""
|
238 | onerror(err, file)
|
239 | } else {
|
240 | res[i] = str
|
241 | err = file.split("?")[0].split(".").pop()
|
242 | if (!raw && err != "js") {
|
243 | xhr[++seq] = str
|
244 | res[i] = "xhr." + err + "(xhr[" + seq + "]);delete xhr[" + seq + "]"
|
245 | }
|
246 | }
|
247 | if (!--pending) {
|
248 | if (!raw) execScript( res.join("/**/;") || ";" )
|
249 | if (next) next(files, res, raw)
|
250 | }
|
251 | }
|
252 | }
|
253 |
|
254 | load(scripts, next)
|
255 |
|
256 | function nop() {}
|
257 | }(this, [/*!{loadFiles}*/])
|
258 |
|