GithubHelp home page GithubHelp logo

headjs / headjs Goto Github PK

View Code? Open in Web Editor NEW
4.2K 4.2K 350.0 2.08 MB

The only script in your HEAD.

Home Page: https://headjs.github.io/

License: MIT License

JavaScript 57.38% CSS 5.51% HTML 35.32% Less 1.78%

headjs's Introduction

This project is no longer maintained, but was the only solution back in the day, to do responsive design with IE6 & co ^^

Latest Version: v1.0.3 :: Docs | Downloads

Responsive Design, Feature Detections, and Resource Loading

  • Speed up your apps: Load JS & CSS asyncronously and in parallel, but execute them in order
  • Load one asset if a condition is met, else fallback and load a different one
  • Manage script dependencies, and execute callbacks once they are loaded
  • Cross-browser compatible « pseudo media-queries » let you code against different resolutions & devices
  • Fix quirks in specific browsers by quickly applying dedicated CSS/JS logic
  • Detect various browsers & their versions
  • Check if the client supports a certain Browser, HTML5, or CSS3 feature
  • Automatically generates JS and CSS classes for browsers & features that where detected
  • Automatically generates CSS classes, to know what page or section a user is viewing
  • Know if the user is in landscape or portrait mode
  • Or whether the client is using a mobile or desktop device
  • Get old browsers to support HTML5 elements like nav, sidebar, header, footer, ...
  • ...
  • Make it, The only script in your <HEAD>
    • A concise solution to universal problems

###Resources

headjs's People

Contributors

robert-hoffmann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

headjs's Issues

document.write compatibility

Is head.js compatible with 3rd party ad scripts which write their content into the page with a document.write statement? I think document.write will only work before rendering is complete which if I understand correctly will not work with head.js? Its a shame because its these ads which often block the rendering of the page making a site feel slow. Any ideas or feedback appreciated.

Error in the documentation for the "Usage" section on the website

In the "Usage" section on http://headjs.com/ these are the final lines of the first set of examples:
// the previous can also be written as
head.js("file1.js").js("file1.js").("file3.js");

The last line should be:
head.js("file1.js").js("file2.js").js("file3.js");

Note the name of the second file, and the method name (which was missing) in the call of the last file.

Request: Load JS/CSS if it was not loaded yet

Many parts of a web are tiny code that need some little js and some little css only for some specific section. So it's crazy to load everything allways.

Head JS should be able to load some script only if it was not loaded before. In this cae the Execute after loaded it's not possible because you will not load the JS allways.

So, for example this

head.js(
{yourscript: "utl/yourscript.js"}, function(){
executesome();
});
head.js(
{yourscript: "utl/yourscript.js"}, function(){
executesomeother();
});

Should not load twice the same script.

And would be also great if this can be applyed to CSS files also for the same reason, you don't need allways all the code present.

Great idea by the way, I started using it :)

head.ready event

Hello Tero Piirainen,

I experienced a little issue. Maybe you came across this.

Unfortunately, I ve to create a little bit of javascript code from the server side.

I wrote something like:

head.ready(function() {
alert("test");
// execute some code here
});

When I push ctrl f5 on my webpage, I get the alert.

When I open the page again, I do not see any alert and firefox says the files are loaded from the cache. Is it possible that the ready event is not thrown in case that all files are loaded from the cache?

Best regards and thank you in advance,

Tobias

Un-named scripts become recursive load nightmare in Firefox

I was checking out your library today, and I noticed some really weird behavior in Firebug on Firefox 3.6. Basically, it appeared as though scripts were getting reloaded recursively, and upon experimentation this caused some really drastic load-time performance degradation. I built the following test cases on jsbin to demonstrate the issue:

http://jsbin.com/eliyu3/edit (load portion of YUI library in three combined groups)
http://jsbin.com/eliyu3/2/edit (load portion of YUI library in 23 non-combined files)

The time to load the JavaScript libraries for me went from ~2 seconds to almost 15 seconds in Firefox 3.6.

I tracked down the issue to the getScript private method in load.js. When passing an array of strings, getScript doesn't properly resolve the key for the "scripts" hash, and so a new object is loaded for all unexecuted scripts on each recursive pass.

Pushed workable fix to my fork, but I didn't do any cross browser testing - you should definitely check it out though. Firefox 3.6 is really unhappy right now ;)

Incomplete HTML5 element styling support in IE

Currently only supports styling of the following HTML5 elements in IE<9:

article, aside, footer, header, nav, section

Should support the same elements found here - http://code.google.com/p/html5shiv/:

abbr, article, aside, audio, canvas, details, figcaption, figure, footer, header, hgroup, mark, meter, nav, output, progress, section, summary, time, video

Issue with jQuery UI?

My usage:

<script src="http://d39fi7w7zolccb.cloudfront.net/head.min.js"></script> <script> head.js("http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"); head.js("http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"); head.js("http://d39fi7w7zolccb.cloudfront.net/fantasy.min.v17.gzip.js"); </script>

When the page loads, the jQuery UI progress bar will render 25% of the time. Same thing happens in every browser I tried to use. I am using inline code for it as follows:

<script> $(function() { $( "#progressbar" ).progressbar({ value: 15 }); }); </script>

Perhaps I am just doing things the wrong way, but I thought I should at least mention it since it renders correctly some of the time.

[Feature Request] - Slimmed down version

I'm very interested in implementing your script, but I really only want to have the js loader portion. Do you plan on, or would you be willing to, have a slimmed down version of the script that only provides the javascript loading functionality?

Feature request: callback for when a script fails loading

I know this project is but a few days old (the internet is amazing, isn't it?!) but as soon as I downloaded it I thought of a feature that would be nice to have. We are using Paul Irish's HTML5 boilerplate, and it has a unique way of loading jQuery which I really like:

<!-- Grab Google CDN's jQuery. fall back to local if necessary -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script>!window.jQuery && document.write('<script src="/javascripts/vendor/jquery-1.4.4.min.js"><\/script>')</script>

So basically what this does is, we first try to load jQuery from Google's CDN. If that times out for some reason, we instead load a local copy of jQuery.

In order to do the same thing with head.js, there could be a 'failure' callback for a file. So I could say something like this:

head.js({
  jquery: "http://http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"
})
head.failure("jquery", function(api) {
  !window.jQuery && api.loadAs('jquery-local', '/javascripts/vendor/jquery-1.4.4.min.js')
})

The intention here is that the callback passed to failure() would get called immediately after the referenced file fails to load, and is passed the global head object; and that the local version of jQuery would be the next file that's loaded. To make that happen, of course, loadAs() (or something like it; don't know if we can reuse .js here) would have to actually insert the given file into the list of files to load instead of merely pushing it (so that it's the next one to load).

So, anyway, I don't know if you see a need for that, but I thought I'd throw it out there.

no-js class at headjs.com

seems like this has been fixed in the dev version, as I can't replicate it there, but it's worth pointing out.

Opera 10/11 beta: scriptTag's cleanup throws DOMException

While testing head.js in the latest Opera, Dragonfly keeps yelling Uncaught exception: [object DOMException] at me. Exception's message is NOT_FOUND_ERR.

The bug can be reproduced on the test page and affects even the stable version.

I have tracked down the source to the line 488:

if (!ie) {
   head.removeChild(elem);
}

Changing the condition to

if (!ie && !opera) {

or putting the call into empty try/catch block silences Dragonfly.

Is it our problem or Opera's?

Problem with HTML5 in IE

Hello.

I just noticed that :

  • head.load.min.js doesn't work for HTML5 in old IE
  • head.min.js does work for HTML5 in old IE

CDN Support

Something very useful, would be if head js knew locations for the CDN(s) of the major libraries (mootools, prototype, jQuery, etc) so you could do something like this:

head.js('jquery'); and that would load jQuery from the google CDN. I know it take quite a bit of work and I'd gladly help (as much as I can :P)

Chaining head.js(): bugs in doc, inconsistencies in function

The docs say that head.js() can be chained like so:

head.js("file1.js").js("file1.js").("file3.js");

There's a typo here: the third chain lacks the function name. In addition, head.js() sometimes returns itself, and sometimes returns the result of queue.push() (the length of the array) which breaks chaining. Also, since the function is returning itself (a function) rather than the api object, the chaining would actually look like this:

head.js("file1.js")("file1.js")("file3.js");

Function should always return api so that chaining works per the docs, which is probably the most logical syntax.

Script errors in IE

Just tried headjs in IE - specifically the demo page with headjs.html
IE 8 (and IE 7 in compatability mode) shows a scripting error.

'null' is null or not an object
prototype.js
line 4125

Cannot easily input text into fields on iPhone

This is specific for iPhone Safari.
My site is using jQuery. I tried using head.js because I wanted to use the classes such as lt-480 to style for different screen sizes (i.e. mobile), but I noticed when head.js was included, more often than not it seemed like I couldn't type into text input fields. I would touch the input field, and a cursor would blink as if I could start typing, but as I type the cursor disappeared as if the field didn't have focus. In order to type in the field, I had to either long press or tap it a few times. When I removed head.js, the field acts as normal. Not sure what is going on here, but it works fine in Android.

Licence?

Hi, I'm curious to know what licence (GPL, MIT etc) you'll be releasing this under? Thanks for an excellent script.

Feature: Add var/option in to load order

It'd be rad to be able to load vars or other option in order as well.

For example. Load jQuery, set the name space, then load a jQuery plugin:

head.js("jquery.min.js",noConflict = jQuery.noConflict(),"plugin.jquery.js");

Screen size detector resizing functionality is not working well

have been playing around lately with headjs but i have found an estranger behavior that i think is not normal. When I'm using the screen size detector for resizing functionality the classes for the size doesn't change as it was expected to adapt to the new size (when you change the size of the window).

Have anyone experienced a similar problem with headjs?

Thanks!

http://stackoverflow.com/questions/4337264/problem-with-headjs-resizer

Duplicate script loads error

Line 441:
if (script.state == 'loaded') { return callback(); }

callback() is undefined. Instead it should be:
if (script.state == 'loaded') {
return callback && callback.call();
}

I created a headjs-rails gem

Hey guys, just wanted to share this little gem I created to easily add Head JS support to Rails 3.

https://github.com/muitocomplicado/headjs-rails

It basically provides a headjs_include_tag helper and a generator to download the latest Head JS files (would be interesting to start tagging releases). The tag helper is a wrapper of javascript_include_tag so it accepts all the default parameters, but it just outputs the Head JS syntax.

It's pretty simple, and actually my first gem. =)

Add support for script concatenation: one URL provides multiple dependencies

WordPress (e.g.) automatically concatenates scripts to reduce HTTP requests, speeding page loads. A single script URL provides many scripts, e.g. jQuery Core and Tools and UI, each of which satisfies different dependencies. The current headjs API provides a one-to-one mapping of labels to scripts.

I propose that headjs should provide a many-to-one mapping. This would improve support for script concatenation. This syntax comes to mind:
// if arg is object and arg.length > 1 then arg is labels and a URL
head.js(["jquery", "tools", "ui", "/path/to/concat.js"]);

head.loader.js IE8 bug

Just a heads up.

I'm testing head.loader.js and IE8 seems to not be loading scripts in order.

head.min.js seems to load everything in order though.

I'm rocking this on something pretty awesome. I'll send it your way when it's all up.

Thanks!

Need DOM ready event included in Head JS

I've read that the $(document).ready() event is now unusable if loading jQuery via Head JS because the DOM ready code completes before any external scripts loaded via Head JS are executed even with head.ready.

Do you think you could include the DOM ready code from jQuery into Head JS file so that you can execute code before the page renders and still load jQuery in parallel? I.e. a dom.ready() function.

Reason I ask is I print a simple red text warning message (in a div) onto the page with the HTML saying "Please enable Javascript for full functionality". Then in the $(document).ready() I set the div's display to none. Effectively if Javascript is enabled you don't see the message at all because it's hidden before the page displays, if Javascript is not enabled you see it. Now I'm not sure that's the standard way to do it, but that's what I devised and I'm open to better suggestions.

With Head JS however you sometimes see a brief flash of the red warning message if you refresh/load the page before it disappears (FUBC). You mention you can avoid this by initially hiding the modifiable elements before the scripts make them visible. However Catch-22 you can't hide the message before the page loads then show the 'Javascript is disabled message' using Javascript after the page has loaded if Javascript is disabled.

Only solution I can think of is to load jQuery directly in the head without Head JS so the DOM ready event works which kinda defeats the purpose of parallel loading as jQuery 1.4.4 is my largest script.

Cheers

Opacity-detection not WebKit-proof

Looking at the source code of head.detect.js, I noticed that you check the status of opacity using
return testAll("opacity:.1");
Now you're likely to fall into the trap jQuery fell into, due to a WebKit bug where locale settings influenced the returned CSS rule: when commas are used as the decimal mark the problematic WebKit-based browsers will return opacity:,1 and your test will fail.

John Resig solved this by using a RegEx instead:
opacity: /^0.55$/.test( a.style.opacity )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.