- browser checks cache; if requested object is in cache and is fresh, skip to #9
- browser asks OS for server's IP address
- OS makes a DNS lookup and replies the IP address to the browser
- browser opens a TCP connection to server (this step is much more complex with HTTPS)
- browser sends the HTTP request through TCP connection
- browser receives HTTP response and may close the TCP connection, or reuse it for another request
- browser checks if the response is a redirect (3xx result status codes), authorization request (401), error (4xx and 5xx), etc.; these are handled differently from normal responses (2xx)
- if cacheable, response is stored in cache
- browser decodes response (e.g. if it's gzipped)
- browser determines what to do with response (e.g. is it a HTML page, is it an image, is it a sound clip?)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
let p = (v) => { | |
return new Promise((resolve, reject) => { | |
setTimeout(resolve, 1000) | |
}).then(() => v) | |
} | |
[1, 2, 3, 4, 5].reduce((seq, curr) => { | |
return seq.then(() => p(curr)).then(console.log) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* @Author: dm.yang | |
* @Date: 2014-09-19 15:40:08 | |
* @Last Modified by: dm.yang | |
* @Last Modified time: 2014-11-06 22:36:51 | |
*/ | |
var uaParser = require('ua-parser'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {HTMLElement} el | |
* @param {String} where beforeBegin、afterBegin、beforeEnd、afterEnd | |
* @param {String} html | |
*/ | |
function insertHTML(el, where, html) { | |
if (!el) return false; | |
where = where.toLowerCase(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 十进制转其他 | |
var x=100; | |
alert(x); | |
alert(x.toString(8)); | |
alert(x.toString(32)); | |
alert(x.toString(16)); | |
//其他转十进制 | |
var x='100'; | |
alert(parseInt(x,2)); | |
alert(parseInt(x,8)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Promise = function () { | |
this.thens = []; | |
}; | |
Promise.prototype = { | |
resolve: function () { | |
var t = this.thens.shift(), n; | |
t && (n = t.apply(null, arguments), n instanceof Promise && (n.thens = this.thens)); | |
}, | |
then: function (n) { |
- 求值:
var n1 = 10;
var n2 = 5;
var r = n1+++n2;
console.log(n1, n2, r); // => 11, 5, 15
- 求值:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//比如在下列A、B、C、D三处转义方式均有细节差异。 | |
//<a href="http://www.qq.com" title="<?=$A?>"><?=$B?></a> | |
//<script>var name="<?=$C?>"</script> | |
//<textarea> | |
//<?=$D?> | |
//</textarea> | |
//进行pre的只能是D,而且还要做其他转义,比如 < 转为 < |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see => http://jsperf.com/postmessage | |
var echoSetTimeout = (function() { | |
return function(msg, cb) { | |
setTimeout(cb, 0); | |
} | |
})(); | |
var echoWorker = (function() { | |
var code = 'onmessage = function(e) { postMessage(e.data) };'; | |
var blobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see => https://github.com/kriskowal/q/blob/v1/q.js#L83 | |
// Use the fastest possible means to execute a task in a future turn | |
// of the event loop. | |
var nextTick =(function () { | |
// linked list of tasks (single, with head node) | |
var head = {task: void 0, next: null}; | |
var tail = head; | |
var flushing = false; | |
var requestTick = void 0; | |
var isNodeJS = false; |
NewerOlder