5 ms·
The only script in your head
- aaront 16y agoVery interesting. Will have to try this for some of my projects.
- dinedal 16y agoI wish it was just the script loading and the other stuff was in a separate library. For a script that purposes to make less loading times I find it ironic that it would also throw in the kitchen sink.
- timmaah 16y agohttps://github.com/headjs/headjs/blob/master/src/head.loader.js https://github.com/headjs/headjs/blob/master/src/head.loader... Head Loader: The ultimate JavaScript loader. Can be used as a standalone tool.
- trafficlight 16y agoAbsolutely. The javascript loader sounds interesting, but I don't need any of the CSS, HTML5 or screen size detection.
- deleted 16y ago[deleted]
- philfreo 16y agoIf all you need is an easy way to asynchronous / lazy load JavaScript, you can just include something like this: http://friendlybit.com/js/lazy-loading-asyncronous-javascript/ http://friendlybit.com/js/lazy-loading-asyncronous-javascrip... Or a nice function, with "Ready" support: In <head>: <script type='text/javascript'> function ljs(s){ var a=document.createElement('script'), b=document.getElementsByTagName('script')[0]; a.type='text/javascript'; a.async=true; a.src=s; b.parentNode.insertBefore(a,b) } var Ready=[]; </script> Then anywhere in the <body> or in any included scripts you can do: Ready.push(function() { //this will get executed after all the ljs files }); Then in a script that contains your JS library, append: $.ready(function() { // or some other ondomready fn // execute all the Ready functions for (var i = 0, m = Ready.length; i < m; i++) { Ready[i](); } delete Ready; });
- deleted 16y ago[deleted]
- kilian 16y agoTry out LABjs: http://labjs.com/ http://labjs.com/
- patrickaljord 16y agoOr http://yepnopejs.com/ http://yepnopejs.com/ it comes with conditional loading, based on labjs.
- storborg 16y agoThe latency difference between an HTTP req for a 2.3K script and a 500 byte script is pretty trivial. And if you're concatenating with other js assets on your site, the incremental increase in size after minification/gzipping will probably be even less than 2.3K.
- chrisbroadfoot 16y agoAgreed. It looked good until I started reading about CSS. The other stuff should be loaded asynchronously, as per their (wise) suggestion
- alanh 16y agoYou don’t understand the philosophy and failed to realize there are already number of scripts that already do this. (Let’s ignore that you you referred to 2K as “the kitchen sink.”) However some things need loaded in he head (for using HTML5 tags in IE, for example). Thus there are obvious efficiencies to be gained by essentially hybridizing Modernizr.js and LABjs. I’m now watching head.js on GitHub, and suggest you reconsider before dismissing it out of hand…
- CWIZO 16y agoThe idea seems nice, I'd have to test it out to actually see if it really delivers. One thing that bugs me tho is the tone of the text. It's all "this is the best thing since sliced bread" and "authors surly must be at least demi-gods". This comment in the page's source says it all really: "headjs :: possibly the most important script after jQuery" I'm all for cocky and confident attitude, I just think it has no place in a presentational web page/docs
- tofumatt 16y agoThe presentation is there to convince you to use their script. I think more OSS libraries and software should convey such an attitude; I'm way more inclined to use software when the authors tell me that it's awesome and why.
- paulirish 16y agoWell it's this author's mistake to be so entirely confident when the library is still full of problems: https://github.com/headjs/headjs/issues#list https://github.com/headjs/headjs/issues#list
- pizzaburger 16y agoSeeing as you opened most of those issues only 5 hours ago, I think you meant to say "the library is full of problems", no?
- Sephr 16y agoI don't understand the whole dynamic class selectors for "Screen size detection". If it's trying to add support for standards, it should support media queries instead.
- alanh 16y agoYour response would be appropriate if we were talking about a new browser but the fact is, virtually no non-Webkit browser, especially on Mobile, supports these media queries. Web dev is all about working with the browsers we’ve got, not the ones we want.
- Sephr 16y agoI'm talking about making headjs add support for media queries (viewport size, at least).
- Griever 16y agoI've been reading up alot on javascript loaders lately to see which one I should use in the webapp I'm currently building. So far I'm checking out LABjs, RequireJS and now apparently headjs. Unfortunately I am not so sure which will suit me best. Has anybody had any luck with any of the aforementioned three?
- bretthopper 16y agoI've used LABjs and it worked great. It's also the most "focused" loader in the sense that it only does javascript loading. RequireJS also includes a module system and some optimization tools. headjs unnecessarily includes CSS feature detection and screen resolution. If you want feature detection, nothing is better than Modernizer: http://www.modernizr.com/ http://www.modernizr.com/
- Griever 16y agoThanks! Yeah I've become quite accustomed to using Modernizr (thanks to inclusion in the Html5Boilerplate). LABjs always seemed like the most straightforward to me, so its nice to hear that others agree :)
- patrickaljord 16y agogive yepnope a try http://yepnopejs.com/ http://yepnopejs.com/
- tjarratt 16y agoI've wanted something exactly like this for a while now. Looking forward to trying this in a few projects over this next week.
- forgotAgain 16y agoIf most of your javascript is made up of libraries like jQuery wouldn't it be simpler to use a free CDN like Google or Microsoft so that the library is most likely already on the user's machine? That would appear to be have a better payback than adding another library to load.
- chrisbroadfoot 16y agoYes. Check out the Google AJAX API. http://code.google.com/apis/loader/index.html http://code.google.com/apis/loader/index.html
- kqueue 16y agoIMHO, websites should include a single js file. In development you can have 100 js files, but in production these should be combined into a single file. The downside is that you might include things you don't need in all pages, but that's not an issue because the file is transferred once, and cached. This will also minimize future conditional GET requests that check wether the cached file has changed or not.
- superk 16y agoI'm not sure I agree with this. I don't think a user should have to re-download all the JS on the site if I just change a single line. Small changes probably happen frequently and shouldn't invalidate the entire JS cache. If I were using a framework like jQuery, I would link that separately from a 3rd-party CDN like Google. Then all the shared behavior would be another request, and page specific code a third. In most cases I would be changing the page specific code which would only invalidate the cache for that request on that page. IMO that's a better compromise.
- tonyskn 16y agoRequireJS does this and includes a module system for managing dependencies. It is also available as a JQuery plugin.
- adamstac 16y agoLogged. http://lg.gd/46 http://lg.gd/46