Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cssrelpreload #129

Merged
merged 5 commits into from
Jun 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"gulp-util": "^3.0.2",
"imageinliner": "^0.2.3",
"indent-string": "^2.1.0",
"inline-critical": "^1.0.0",
"inline-critical": "^2.1.5",
"lodash": "^4.0.0",
"meow": "^3.3.0",
"mime-types": "^2.1.6",
Expand Down
9 changes: 9 additions & 0 deletions test/05-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ describe('CLI', function () {

var expected = fs.readFileSync(path.join(__dirname, 'expected/generate-default.css'), 'utf8');
cp.stdout.on('data', function (data) {
if (data instanceof Buffer) {
data = data.toString('utf8');
}
assert.strictEqual(nn(data), nn(expected));
done();
});
Expand All @@ -62,6 +65,9 @@ describe('CLI', function () {

var expected = fs.readFileSync(path.join(__dirname, 'expected/generate-default.css'), 'utf8');
cp.stdout.on('data', function (data) {
if (data instanceof Buffer) {
data = data.toString('utf8');
}
assert.strictEqual(nn(data), nn(expected));
done();
});
Expand Down Expand Up @@ -105,6 +111,9 @@ describe('CLI', function () {

var expected = fs.readFileSync(path.join(__dirname, 'expected/generate-default.css'), 'utf8');
cp.stdout.on('data', function (data) {
if (data instanceof Buffer) {
data = data.toString('utf8');
}
assert.strictEqual(nn(data), nn(expected));
done();
});
Expand Down
17 changes: 7 additions & 10 deletions test/expected/generate-ignorefont.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
<meta charset="UTF-8">
<title>Font-face</title>
<style type="text/css">
body {
font-family: 'PT Sans', sans-serif;
}
</style>
<script id="loadcss">
(function(u,s){!function(e){"use strict";var n=function(n,t,o){var l,r=e.document,i=r.createElement("link");if(t)l=t;else{var a=(r.body||r.getElementsByTagName("head")[0]).childNodes;l=a[a.length-1]}var d=r.styleSheets;i.rel="stylesheet",i.href=n,i.media="only x",l.parentNode.insertBefore(i,t?l:l.nextSibling);var f=function(e){for(var n=i.href,t=d.length;t--;)if(d[t].href===n)return e();setTimeout(function(){f(e)})};return i.onloadcssdefined=f,f(function(){i.media=o||"all"}),i};"undefined"!=typeof module?module.exports=n:e.loadCSS=n}("undefined"!=typeof global?global:this);for(var i in u){loadCSS(u[i],s);}}(['styles/font.css'],document.getElementById("loadcss")));
</script>
<noscript>
<link rel="stylesheet" href="styles/font.css">
</noscript>
body {
font-family: 'PT Sans', sans-serif;
}
</style>
<link rel="preload" href="styles/font.css" as="style" onload="this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="styles/font.css"></noscript>
<script>!function(e){"use strict";var t=function(t,n,r){function o(e){return i.body?e():void setTimeout(function(){o(e)})}function a(){d.addEventListener&&d.removeEventListener("load",a),d.media=r||"all"}var l,i=e.document,d=i.createElement("link");if(n)l=n;else{var s=(i.body||i.getElementsByTagName("head")[0]).childNodes;l=s[s.length-1]}var u=i.styleSheets;d.rel="stylesheet",d.href=t,d.media="only x",o(function(){l.parentNode.insertBefore(d,n?l:l.nextSibling)});var f=function(e){for(var t=d.href,n=u.length;n--;)if(u[n].href===t)return e();setTimeout(function(){f(e)})};return d.addEventListener&&d.addEventListener("load",a),d.onloadcssdefined=f,f(a),d};"undefined"!=typeof exports?exports.loadCSS=t:e.loadCSS=t}("undefined"!=typeof global?global:this),function(e){if(e.loadCSS){var t=loadCSS.relpreload={};if(t.support=function(){try{return e.document.createElement("link").relList.supports("preload")}catch(t){return!1}},t.poly=function(){for(var t=e.document.getElementsByTagName("link"),n=0;n<t.length;n++){var r=t[n];"preload"===r.rel&&"style"===r.getAttribute("as")&&(e.loadCSS(r.href,r),r.rel=null)}},!t.support()){t.poly();var n=e.setInterval(t.poly,300);e.addEventListener&&e.addEventListener("load",function(){e.clearInterval(n)}),e.attachEvent&&e.attachEvent("onload",function(){e.clearInterval(n)})}}}(this);</script>
</head>
<body>
<h1>should be styled by @font-face</h1>
Expand Down
21 changes: 9 additions & 12 deletions test/expected/generateInline-external-extract.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@

<!-- build:css styles/main.css -->
<style type="text/css">
.header,.jumbotron{border-bottom:1px solid #e5e5e5}.btn,.jumbotron{text-align:center}body{padding-top:20px;padding-bottom:20px}.header,.marketing{padding-left:15px;padding-right:15px}.header h3{margin-top:0;margin-bottom:0;line-height:40px;padding-bottom:19px}.jumbotron .btn{font-size:21px;padding:14px 24px}.marketing{margin:40px 0}@media screen and (min-width:768px){.container{max-width:730px}.header,.marketing{padding-left:0;padding-right:0}.header{margin-bottom:30px}.jumbotron{border-bottom:0}}.col-lg-6,.container{padding-right:15px;padding-left:15px}html{font-family:sans-serif;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;font-size:62.5%}body{margin:0;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px;line-height:1.42857143;color:#333;background-color:#fff}a{background:0 0;color:#428bca;text-decoration:none}h1{margin:.67em 0;font-size:36px}h1,h3,h4{margin-bottom:10px;font-family:inherit;font-weight:500;line-height:1.1;color:inherit}*,:after,:before{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}h1,h3{margin-top:20px}h3{font-size:24px}h4{margin-top:10px;font-size:18px}p{margin:0 0 10px}.lead{margin-bottom:20px;font-size:16px;font-weight:200;line-height:1.4}.text-muted{color:#999}ul{margin-top:0;margin-bottom:10px}.btn,.nav{margin-bottom:0}.container{margin-right:auto;margin-left:auto}@media (min-width:768px){.lead{font-size:21px}.container{width:750px}}@media (min-width:992px){.container{width:970px}}.row{margin-right:-15px;margin-left:-15px}.col-lg-6{position:relative;min-height:1px}@media (min-width:1200px){.container{width:1170px}.col-lg-6{float:left;width:50%}}.btn{display:inline-block;padding:6px 12px;font-size:14px;font-weight:400;line-height:1.42857143;white-space:nowrap;vertical-align:middle;background-image:none;border:1px solid transparent;border-radius:4px}.nav>li,.nav>li>a{position:relative;display:block}.btn-success{color:#fff;background-color:#5cb85c;border-color:#4cae4c}.btn-lg{padding:10px 16px;font-size:18px;line-height:1.33;border-radius:6px}.nav{padding-left:0;list-style:none}.nav>li>a{padding:10px 15px}.nav-pills>li{float:left}.nav-pills>li>a{border-radius:4px}.nav-pills>li+li{margin-left:2px}.nav-pills>li.active>a{color:#fff;background-color:#428bca}.jumbotron,.jumbotron h1{color:inherit}.jumbotron{padding:30px;margin-bottom:30px;background-color:#eee}.jumbotron p{margin-bottom:15px;font-size:21px;font-weight:200}.container .jumbotron{border-radius:6px}@media screen and (min-width:768px){.jumbotron{padding-top:48px;padding-bottom:48px}.container .jumbotron{padding-right:60px;padding-left:60px}.jumbotron h1{font-size:63px}}.container:after,.container:before,.nav:after,.nav:before,.row:after,.row:before{display:table;content:" "}.container:after,.nav:after,.row:after{clear:both}.pull-right{float:right!important}@-ms-viewport{width:device-width}
</style>
<script id="loadcss">
(function(u,s){!function(e){"use strict";var n=function(n,t,o){var l,r=e.document,i=r.createElement("link");if(t)l=t;else{var a=(r.body||r.getElementsByTagName("head")[0]).childNodes;l=a[a.length-1]}var d=r.styleSheets;i.rel="stylesheet",i.href=n,i.media="only x",l.parentNode.insertBefore(i,t?l:l.nextSibling);var f=function(e){for(var n=i.href,t=d.length;t--;)if(d[t].href===n)return e();setTimeout(function(){f(e)})};return i.onloadcssdefined=f,f(function(){i.media=o||"all"}),i};"undefined"!=typeof module?module.exports=n:e.loadCSS=n}("undefined"!=typeof global?global:this);for(var i in u){loadCSS(u[i],s);}}(['styles/main.b5ff4680.css','styles/bootstrap.cce7f1a3.css','//fonts.googleapis.com/css?family=Merriweather:300,700,700italic,300italic|Open+Sans:700,400'],document.getElementById("loadcss")));
</script>
<noscript>
<link rel="stylesheet" href="styles/main.b5ff4680.css">
<link rel="stylesheet" href="styles/bootstrap.cce7f1a3.css">
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Merriweather:300,700,700italic,300italic|Open+Sans:700,400">
</noscript>


.header,.jumbotron{border-bottom:1px solid #e5e5e5}.btn,.jumbotron{text-align:center}body{padding-top:20px;padding-bottom:20px}.header,.marketing{padding-left:15px;padding-right:15px}.header h3{margin-top:0;margin-bottom:0;line-height:40px;padding-bottom:19px}.jumbotron .btn{font-size:21px;padding:14px 24px}.marketing{margin:40px 0}@media screen and (min-width:768px){.container{max-width:730px}.header,.marketing{padding-left:0;padding-right:0}.header{margin-bottom:30px}.jumbotron{border-bottom:0}}.col-lg-6,.container{padding-right:15px;padding-left:15px}html{font-family:sans-serif;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;font-size:62.5%}body{margin:0;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px;line-height:1.42857143;color:#333;background-color:#fff}a{background:0 0;color:#428bca;text-decoration:none}h1{margin:.67em 0;font-size:36px}h1,h3,h4{margin-bottom:10px;font-family:inherit;font-weight:500;line-height:1.1;color:inherit}*,:after,:before{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}h1,h3{margin-top:20px}h3{font-size:24px}h4{margin-top:10px;font-size:18px}p{margin:0 0 10px}.lead{margin-bottom:20px;font-size:16px;font-weight:200;line-height:1.4}.text-muted{color:#999}ul{margin-top:0;margin-bottom:10px}.btn,.nav{margin-bottom:0}.container{margin-right:auto;margin-left:auto}@media (min-width:768px){.lead{font-size:21px}.container{width:750px}}@media (min-width:992px){.container{width:970px}}.row{margin-right:-15px;margin-left:-15px}.col-lg-6{position:relative;min-height:1px}@media (min-width:1200px){.container{width:1170px}.col-lg-6{float:left;width:50%}}.btn{display:inline-block;padding:6px 12px;font-size:14px;font-weight:400;line-height:1.42857143;white-space:nowrap;vertical-align:middle;background-image:none;border:1px solid transparent;border-radius:4px}.nav>li,.nav>li>a{position:relative;display:block}.btn-success{color:#fff;background-color:#5cb85c;border-color:#4cae4c}.btn-lg{padding:10px 16px;font-size:18px;line-height:1.33;border-radius:6px}.nav{padding-left:0;list-style:none}.nav>li>a{padding:10px 15px}.nav-pills>li{float:left}.nav-pills>li>a{border-radius:4px}.nav-pills>li+li{margin-left:2px}.nav-pills>li.active>a{color:#fff;background-color:#428bca}.jumbotron,.jumbotron h1{color:inherit}.jumbotron{padding:30px;margin-bottom:30px;background-color:#eee}.jumbotron p{margin-bottom:15px;font-size:21px;font-weight:200}.container .jumbotron{border-radius:6px}@media screen and (min-width:768px){.jumbotron{padding-top:48px;padding-bottom:48px}.container .jumbotron{padding-right:60px;padding-left:60px}.jumbotron h1{font-size:63px}}.container:after,.container:before,.nav:after,.nav:before,.row:after,.row:before{display:table;content:" "}.container:after,.nav:after,.row:after{clear:both}.pull-right{float:right!important}@-ms-viewport{width:device-width}
</style>
<link rel="preload" href="styles/main.b5ff4680.css" as="style" onload="this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="styles/main.b5ff4680.css"></noscript>
<link rel="preload" href="styles/bootstrap.cce7f1a3.css" as="style" onload="this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="styles/bootstrap.cce7f1a3.css"></noscript>
<link rel="preload" type="text/css" href="//fonts.googleapis.com/css?family=Merriweather:300,700,700italic,300italic|Open+Sans:700,400" as="style" onload="this.rel='stylesheet'">
<noscript><link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Merriweather:300,700,700italic,300italic|Open+Sans:700,400"></noscript>
<script>!function(e){"use strict";var t=function(t,n,r){function o(e){return i.body?e():void setTimeout(function(){o(e)})}function a(){d.addEventListener&&d.removeEventListener("load",a),d.media=r||"all"}var l,i=e.document,d=i.createElement("link");if(n)l=n;else{var s=(i.body||i.getElementsByTagName("head")[0]).childNodes;l=s[s.length-1]}var u=i.styleSheets;d.rel="stylesheet",d.href=t,d.media="only x",o(function(){l.parentNode.insertBefore(d,n?l:l.nextSibling)});var f=function(e){for(var t=d.href,n=u.length;n--;)if(u[n].href===t)return e();setTimeout(function(){f(e)})};return d.addEventListener&&d.addEventListener("load",a),d.onloadcssdefined=f,f(a),d};"undefined"!=typeof exports?exports.loadCSS=t:e.loadCSS=t}("undefined"!=typeof global?global:this),function(e){if(e.loadCSS){var t=loadCSS.relpreload={};if(t.support=function(){try{return e.document.createElement("link").relList.supports("preload")}catch(t){return!1}},t.poly=function(){for(var t=e.document.getElementsByTagName("link"),n=0;n<t.length;n++){var r=t[n];"preload"===r.rel&&"style"===r.getAttribute("as")&&(e.loadCSS(r.href,r),r.rel=null)}},!t.support()){t.poly();var n=e.setInterval(t.poly,300);e.addEventListener&&e.addEventListener("load",function(){e.clearInterval(n)}),e.attachEvent&&e.attachEvent("onload",function(){e.clearInterval(n)})}}}(this);</script>
<!-- endbuild -->

</head>
Expand Down
Loading