Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

20 Commits

Repository files navigation

insert-css

insert a string of css into the <head>

browser support

example

suppose we've got some css:

body {
background-color: purple;
color: yellow;
}

and we want to bundle that css into a js file so that we can write an entirely self-contained module:

varfs=require('fs');varinsertCss=require('insert-css');varcss=fs.readFileSync(__dirname+'/style.css');insertCss(css);document.body.appendChild(document.createTextNode('HELLO CRUEL WORLD'));

optionally prepend the css to the head with the prepend option:

insertCss(css,{prepend: true});

compile with browserify using brfs to inline the fs.readFile() call:

$ browserify -t brfs insert.js > bundle.js

Now plop that bundle.js into a script tag and you'll have a self-contained js blob with inline css!

<html><head></head><body><scriptsrc="bundle.js"></script></body></html>

About

insert a string of css into the <head>

Resources

Stars

0 stars

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages