We have a Line it! share button on our page, it is blocking loading of our own resources with is causing a big performance issue.
With the implementation of the Line Share button proposed by line.me their line-button.js script needs to be included in the middle of the page, where ever the button should be shown. The button replaces the <script>
element from where it's initiated:
<script type="text/javascript">
new media_line_me.LineButton({"pc":false,"lang":"en","type":"b"});
</script>
I can add the line-button.js script to the page after our own have completed:
function includeLine(callback) {
var script = document.createElement('script');
script.async = true;
script.onload = callback;
script.src = "//media.line.me/js/line-button.js?v=20140411";
document.body.appendChild(script);
}
Then I can inject the script element like this:
function initLine() {
var
script = document.createElement('script'),
line = ['new media_line_me.LineButton({"pc":false,"lang":"'];
line.push(util.getLang());
line.push('","type":"b"});');
script.text = line.join('');
publ.$elements.shareLine.append(script);
};
But in line-button.js media_line_me.LineButton
attaches a listener to the window.onload
event, which by this time has already happened.
I really want to make sure that everything else is done before any social media widgets start to load. But right now I'm kind of out of ideas.
Is there another solution to this that's not loading the JS file as text, rewriting it in our script and then eval()
it?