1.0.1 • Published 8 years ago

recreate-elements-script-tags v1.0.1

Weekly downloads
4
License
ISC
Repository
github
Last release
8 years ago

Recreate Elements Script Tags

This function will traverse a element, any script tags it finds inside will be recreated. Returns a bluebird promise so you know, if you care, when all the script tags are finished loading.

So, the issue is that if you want to use innerHTML to render a html partial within you application AND that partial has some script tags in it for its own Javascript dependencies. You will have a problem. Read this one.

The DOM will not recognize script tags added via innerHTML, well, not in any way that you care about.

But How?

Aight, its a module.exports style module, so use browserify or webpack.

var recreateElementsScriptTags = require('recreate-elements-script-tags');

getPagePartialFromServer()
    .then(function(partial) {
        document.querySelector('#stage').innerHTML = partial;

        recreateElementsScriptTags(document.querySelector('#stage'))
            .then(function() {
                // DONE!
            });
    });

Let me know how it goes.