Skip to content

Commit 4fd0718

Browse files
committed
allow for async css loading
1 parent 59e6c03 commit 4fd0718

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ npm install --save create-html
3131
- `script`
3232
- `scriptAsync`
3333
- `css`
34+
- `cssAsync`
3435
- `lang`
3536
- `dir`
3637
- `head`

cli.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var argv = parseArgs(process.argv.slice(2), {
1414
H: 'head',
1515
f: 'favicon',
1616
c: 'css',
17+
C: ['css-async', 'cssAsync'],
1718
s: 'script',
1819
a: ['script-async', 'scriptAsync'],
1920
o: 'output',
@@ -23,7 +24,8 @@ var argv = parseArgs(process.argv.slice(2), {
2324
'output'
2425
],
2526
boolean: [
26-
'script-async'
27+
'script-async',
28+
'css-async'
2729
]
2830
})
2931

@@ -36,6 +38,7 @@ Options:
3638
--script, -s JavaScript filename, optional
3739
--script-async, -a Add async attribute to script tag
3840
--css, -c CSS filename, optional
41+
--css-async, -C Load CSS asynchronously
3942
--favicon, -f Site favicon
4043
--lang, -l Language of content
4144
--dir, -d Direction of content

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ module.exports = function (opts) {
33
var headScript = (opts.script && opts.scriptAsync) ? `<script src="${opts.script}" async></script>` : ''
44
var bodyScript = (opts.script && !opts.scriptAsync) ? `<script src="${opts.script}"></script>` : ''
55
var favicon = opts.favicon ? `<link rel="icon" href="${opts.favicon}">` : ''
6-
var css = opts.css ? `<link rel="stylesheet" href="${opts.css}">` : ''
6+
var css = opts.css
7+
? opts.cssAsync
8+
? `<link rel="stylesheet" href="${opts.css}" media="none" onload="if(media!=='all')media='all'">`
9+
: `<link rel="stylesheet" href="${opts.css}">`
10+
: ''
711
var lang = opts.lang || 'en'
812
var dir = opts.dir || 'ltr'
913
var head = opts.head || ''

0 commit comments

Comments
 (0)