socketstream / html-tag-injector

Injects asset tags (e.g. CSS and JS) into a HTML document

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HTML Asset Tag Injector

Injects asset tags (e.g. <script> and <link>) inside a given HTML document in the most optimal place.

Outputs original HTML with top tags (typically CSS) and bottom tags (typically JS) correctly inserted.

## Example

var injector = require('html-tag-injector');

var input = fs.readFileSync('any.html', 'utf8');
var output = injector(input, {
  top:    '<link rel="stylesheet" type="text/css" href="my.css">'
  bottom: '<script type="text/javascript" src="/myscript.js">'
});

Status

This module is a work in progress. It's possible we'll need to move to a real HTML parser (like htmlparser2) instead of simple string substation in the future.

Pull requests appreciated. Please be sure to create test cases (it's easy).

Tests

To run tests:

mocha

Licence

MIT

About

Injects asset tags (e.g. CSS and JS) into a HTML document


Languages

Language:JavaScript 100.0%