Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

LAB inserts scripts at the beginning of the <head> #115

Closed
xaddict opened this issue Mar 25, 2016 · 7 comments
Closed

LAB inserts scripts at the beginning of the <head> #115

xaddict opened this issue Mar 25, 2016 · 7 comments

Comments

@xaddict
Copy link

xaddict commented Mar 25, 2016

LABjs insert scripts at the beginning of the instead of at the end of the or even the end of the tag. Is there a reason for this and could it be changed in upcoming versions?

@devilking15292
Copy link

if you want to add the downloaded scripts to the end of the head tag .. just open LAB.src.js
and replace this line

append_to.insertBefore(script,append_to.firstChild);
with
append_to.appendChild(script);

in line numbers 174, 183, 190 and 244.

hope it satisfies your need ..

Note: this is a non tested solution .

@getify
Copy link
Owner

getify commented Mar 25, 2016

@xaddict why does it matter where LABjs adds the scripts?

@xaddict
Copy link
Author

xaddict commented Mar 30, 2016

Well, for one, Audits by Google wants scripts in a certain place and having
to ignore a bunch of rules just because LABjs does it that way can be
annoying if you have loads of projects all running through audits and
pagespeed. Plus, it's common esthetic practice to not put them before the
title or base tags
On Fri, 25 Mar 2016 at 19:38 Kyle Simpson notifications@github.com wrote:

@xaddict https://github.com/xaddict why does it matter where LABjs adds
the scripts?


You are receiving this because you were mentioned.

Reply to this email directly or view it on GitHub
#115 (comment)

@getify
Copy link
Owner

getify commented Mar 30, 2016

Those audits or whatever they are, are being rather naive if they're penalizing you for dynamically added scripts in the <head>. It's true it's not a great idea for that in the orig source code, but this is all dynamic, so its placement won't have any difference or impact at all.

Not sure this kind of feature would be useful to a broad enough audience to make it worth the bytes. But perhaps.

Ema4rl added a commit to Ema4rl/Only.js that referenced this issue May 26, 2016
Improved on LABjs by adding:
-> conditional loading based on element availability
-> test multiple elements with AND-like condition (eg:
$O.test().test().js().wait())
-> test multiple elements with OR-like condition (eg: $O.test('this,
that').js().wait())
-> custom javascript attributes
-> leaner code (6.3kb minified, 2.9kb gzipped)
-> replaces .no-js with .js on html element
-> queue test via $O.queueTest()
-> end() to enable explicit end of test chain without breaking the chain
(unlike sandbox())
-> loading initial js (entry point js - like app.js) via data attribute
with data-only
-> adjusted absolute uri regex gotten from a LABjs issue
(getify/LABjs#98)
-> automatically load polyfill service (polyfill.io) via options
-> inject script tags at end of head tag opposed to LABjs inject at top
(getify/LABjs#115)
-> conditional script execution of inline scripts via $O.test().script()
-> add snippet in docs for lazy css since this library will not handle
that
-> support CommonJS (not tested)
@getify
Copy link
Owner

getify commented Apr 3, 2017

LABjs is going to append resource requests to the end of the <head> from 3.0 onward.

@getify getify closed this as completed Apr 3, 2017
@tonyporto
Copy link

Thank you for all the work you put into this, I actively use labjs & great to see that your back to actively making it better then what it already is...

@xaddict
Copy link
Author

xaddict commented May 11, 2017

Awesome!

@getify
I hate to be a stick-in-the-mud but could it be an option to add resources to:

  1. the end of the <head>
  2. the end of the <body>

I know LABjs is async and deferred by design (defer the loading of LABjs and the script that calls LABjs) but PageSpeed Insights, WooRank, Feed the Bot, and other SEO tools are real bitches about order and placement of inserted scripts. For example, scripts that are before stylesheets or in order one after another (script, stylesheet, script, stylesheet) negatively impact the reports from these tools. It's very annoying but could be stopped by injecting scripts at the end of the <body> and stylesheets at the end of the <head>.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants