Skip to content

Instantly share code, notes, and snippets.

@hxgdzyuyi
Last active Aug 29, 2015
Embed
What would you like to do?
测试 浏览器 loading 标志

测试 浏览器 loading 标志

var express = require("express")
, app = express()
app.set('views', __dirname)
app.set('view engine', 'jade');
app.get("/domready", function(request, response) {
response.render("domready");
})
app.get("/set_timeout", function(request, response) {
response.render("set_timeout");
})
app.get("/set_timeout_and_domready", function(request, response) {
response.render("set_timeout_and_domready");
})
app.get("/sleep_five", function(request, response) {
response.setTimeout(5000, function() {
response.contentType("text/javascript");
response.send('console.log(1)');
})
})
app.listen(3001)
html
head
title - My
script(type='text/javascript').
(function (fn) {
var listener
, doc = document
, domContentLoaded = 'DOMContentLoaded'
, loaded = /^loaded|^i|^c/.test(doc.readyState);
if (!loaded){
doc.addEventListener(domContentLoaded, listener = function () {
doc.removeEventListener(domContentLoaded, listener)
loaded = 1
fn()
});
} else {
fn()
}
})(function () {
var global = window;
var newNode = global.document.createElement('script')
, existingNode = global.document.getElementsByTagName('script')[0]
newNode.setAttribute('type', 'text/javascript');
newNode.setAttribute('src', '/sleep_five');
newNode.setAttribute('async', true);
existingNode.parentNode.insertBefore(newNode, existingNode);
});
html
head
title - My
script(type='text/javascript').
setTimeout(function(){
var global = window;
var newNode = global.document.createElement('script')
, existingNode = global.document.getElementsByTagName('script')[0]
newNode.setAttribute('type', 'text/javascript');
newNode.setAttribute('src', '/sleep_five');
newNode.setAttribute('async', true);
existingNode.parentNode.insertBefore(newNode, existingNode);
}, 0)
html
head
title - My
script(type='text/javascript').
(function (fn) {
var listener
, doc = document
, domContentLoaded = 'DOMContentLoaded'
, loaded = /^loaded|^i|^c/.test(doc.readyState);
if (!loaded){
doc.addEventListener(domContentLoaded, listener = function () {
doc.removeEventListener(domContentLoaded, listener)
loaded = 1
fn()
});
} else {
fn()
}
})(function () {
setTimeout(function() {
var global = window;
var newNode = global.document.createElement('script')
, existingNode = global.document.getElementsByTagName('script')[0]
newNode.setAttribute('type', 'text/javascript');
newNode.setAttribute('src', '/sleep_five');
newNode.setAttribute('async', true);
existingNode.parentNode.insertBefore(newNode, existingNode);
}, 0)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment