Coder Social home page Coder Social logo

yepnope.js's Introduction

Build Status

Deprecation Notice

TL;DR: we've replaced what yepnope used to do with a very minimal script to help you do what we think is best for your apps.

The authors of yepnope feel that the front-end community now offers better software for loading scripts, as well as conditionally loading scripts. None of the APIs for these new tools are quite as easy as yepnope, but we assure you that it's probably worth your while. We don't officially endorse any replacement, however we strongly suggest you follow an approach using modules, and then package up your application using require.js, webpack, browserify, or one of the many other excellent dependency managed build tools.

When it comes to loading things conditionally, we suggest that you output a build for each combination of the things you're testing. This might sound like it will generate a lot of files (it might), but computers are pretty good at that. Then you can inline a script into your page that only loads (asynchronously!) a single built script that is tuned to the features of that user. All the performance win of conditional loading, and none of the latency problems of loading 100 things at once.

We have replaced this repo with a script that will help you load the correct conditional build and will only be taking issues and pull requests for this new script. It retains many of the original functions and features as the original yepnope. However it no longer executes scripts in an order. If you're looking for something that specifically does that, you can use an old version of yepnope, or another in-order script loader like LABjs.

For these reasons, we're also not going to include yepnope in the next version of Modernizr as Modernizr.load.

yepnope.js

A Script Loader For Your Conditional Builds

By @SlexAxton and @rlph

Example

// It will Do The Right Thing™ with a .js or .css extension
yepnope('script.js', {
  modernimages: Modernizr.webp && Modernizr.apng,
  css3: Modernizr.borderradius && Modernizr.boxshadow,
  consoleapis: window.console && window.console.log
});

And a request for script.js?yep=css3,consoleapis&nope=modernimages would be made (assuming that set of results).

It's up to you to serve the correct build file from that url (you should statically build and/or cache this endpoint)

With Modernizr

If you're running a custom build of Modernizr (version 3+), the only "own properties" of the Modernizr object are the tests. All other properties are stored on the prototype. Because of this, you can easily just pass yepnope your Modernizr object, and not have to worry about creating a test object.

yepnope('build.js', Modernizr, function() {
  MyApp.init();
});

Just regular script and css injection

We also expose our underlying script and css injection functions as

  • yepnope.injectJs
  • yepnope.injectCss (The callback does not wait for the css to actually be loaded)

The tests are a good place to look at the uses.

Customizing the generated URL

If you need the generated URL from the tests to look a certain way, feel free to override the yepnope.urlFormatter function.

// change it to only output passing tests, as dashes on the file name
yepnope.urlFormatter = function(url, tests) {
  var parts = url.split('.');
  var extension = parts.pop();
  var filename = parts.join('.');
  var passes = [];

  if (tests) {
    for(var testname in tests) {
      if (tests.hasOwnProperty(testname) && tests[testname]) {
        passes.push(testname);
      }
    }
  }
  if (passes.length) {
    return filename + '-' + passes.join('-') + '.' + extension;
  }
  return url;
};

Then the url generated from the first example above would be: script-css3-consoleapis.js

Building and Testing

# Clone the repo
git clone [email protected]:SlexAxton/yepnope.js.git

# Go inside of it
cd yepnope.js

# Optionally switch branches
git checkout <the-branch-you-want>

# Install the dependencies
npm install

# Run the tests
grunt test

# In order to view them in a browser
grunt serve

# Open the test url in a browser
open http://127.0.0.1:3333/test/

# Run the tests and build
grunt

Your build will be in the dist/ folder.

CHANGELOG

Version 2 is a significant diversion from Version 1.x. We feel that the direction helps developers make the best decisions for performance rather than enabling poor uses.

Changes in 2.0+ :

  • Rewrote entire library
  • Relicensed to New BSD
  • Deprecated Library

License

BSD-3-Clause License

Copyright (c) 2014, Alex Sexton
Copyright (c) 2014, Ralph Holzmann
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

##Thanks##

  • Dave Artz - A.getJS was a huge code-inspiration for our loader. So he's responsible for a ton of awesome techniques here.
  • Kyle Simpson - He is the creator of LABjs of which a lot of this is inspired by.
  • Stoyan Stefanov - His work on resource preloading has been awesome: http://www.phpied.com/preload-cssjavascript-without-execution/
  • Steve Souders - His evangelism and work in the space (ControlJS) have brought light to the issues at hand, he is the father of front-end performance.

yepnope.js's People

Contributors

bugdebugger avatar crodas avatar davidpadbury avatar designbyonyx avatar dmitrybaranovskiy avatar ixti avatar james-stephenson avatar kennethkufluk avatar knpwrs avatar mjc-gh avatar patmoore avatar peeter-tomberg avatar peterdavehello avatar slexaxton avatar stristr avatar timoxley avatar yousseftaghlabi 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

yepnope.js's Issues

{load:[array]} different complete behaviour to [{load:string}] on Android

My main.js required both HistoryJS and jQuery, and my HistoryJS file needs jQuery. I also need JSON and XSLT...
Anyway, I have been using the following YepNope style, featuring a "load" property with an array of URL strings:

Modernizr.load([{
  test: window.JSON,
  nope: 'json2.js'
}, {
  test: window.XSLTProcessor,
  nope: 'ajaxslt-0.8.1-r61.min.js'
}, {
  load: [ 'jquery-1.6.1.min.js', 'history-1.7.0.min.js', 'main.js' ],
  complete: function() { onMainLoad(); }
}]);

However, I've noticed that onMainLoad() was being called out of sequence, often before main.js had even defined it. After clearing my cache, I would even get errors about HistoryJS loading before jQuery was available. This was on Android, by the way, with the worst web browser ever built by Google.

So as an experiment, I changed it to look like this:

Modernizr.load([{
  test: window.JSON,
  nope: 'json2.js'
}, {
  test: window.XSLTProcessor,
  nope: 'ajaxslt-0.8.1-r61.min.js'
}, {
  load: 'jquery-1.6.1.min.js'
}, {
  load: 'history-1.7.0.min.js'
}, {
  load: 'main.js',
  complete: function() { onMainLoad(); }
}]);

Now it works perfectly on Android and other browsers. I'm not sure where I first came across that first style, but it's not on the official website. I guess that should have been a hint that it was the wrong way to do something. However, I just thought I'd bring this up in case both styles were perfectly valid. Does feeding an array into "load" change the sequence somehow? Or is the timing being thrown off by a slow JIT compiler or something in Android?

Hangs when loading empty CSS file.

The loader hangs when a css file that does not have any content or no valid tags.

I.e. a blank file files or a file only containing "body"

However, simply adding: body{ or body{} will fix the issue.

I've observed this on the latest build of Chrome Dev channel.

In development it's common to load a file that temporarily doesn't have any content. I realize this is a bit of an edge case but it would be nice if it worked.

jquery-ui.css from ajax.googleapis.com loads, but also times out?

I made small test to show what I'm talking about: http://sembiki.github.com/meemoo/test/yepnope-jqueryui.html

Consistently takes ~10 seconds to say "Done," and it only seems to be an issue with jquery-ui.css. I got around it in my app by loading jquery-ui.css in the complete: function, so it doesn't block anything after it, but I'm not sure what the issue is. Why would jquery-ui.css from ajax.googleapis.com be timing out?

yepnope({
  test : true,
  yep  : [
    'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js',
    'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js',
    'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/themes/eggplant/jquery-ui.css'
  ],
  complete : function(){
    $(document).ready(function() {
      document.getElementById("status").innerHTML += "Done.";
    });
  }
});

Load Array Object and execute on Complete

Hi, congratulation for yepnope, it's fantastic!

I tryed the following

   var toload = ['some.js', 'some.css']
yepnope({
    load: toload,
    complete: function () {
        console.log('done');
    }
});

And doesn't work. If I use a callback instead it works. Is this a bug or I'm doing something wrong. Thanks!

Modernizr.load/yepnope fails to execute if file loads too slow

When throttling download speeds I've encountered a bug where the javascript loaded with modernizr.load doesn't get executed. To narrow down the error I've created the following html:

<!doctype html>
<html>
<head>
<script src='yepnope.1.0.2-min.js'></script>
</head>
<body>
<script>yepnope('SlowLoadingJavascript.js')</script>
</body>
</html>

The SlowLoadingJavasript.js is some 150kbyte large, and the connection speed throttled to 256kbit/s and lower. When the download speed is throttled until loading the javascript takes at least 10 seconds to load it stops to execute. Switching modernizr for the newest version of yepnope doesn't change things.

I've tested it in Chrome 14.0.835.202 m and in Firefox 7.0.1, but it also happens on all IE versions.

In both Firebug and Chrome devtools the second load doesn't show up any longer.

As soon as the file comes from cache - which it does on second page load - it does execute.

google api fallback - test: not working

i'm trying to setup a google api fallback in case jquery is not loaded correctly from google cdn. seems to me the test of yep nope does not work, it's always nope:

yepnope([
{
    load: 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js',
    wait: true,
    callback: function(){
        console.log( typeof jQuery == 'function' );
    }
},
{
    test: typeof jQuery == 'function',
    nope: ['wait!js/jquery-1.4.4.min.js']           
}
]); 

Scripts appear in Firebug to load twice

I haven't tested thoroughly whether this is happening in other browser dev tools, but it appears in the Firebug Net panel that scripts loaded with yepnope are loading twice. Furthermore, the HTML tab doesn't seem to display the updated HTML containing the dynamic script tags.

Imbricked calls

Not sure if it's me that's doing something wrong but here goes:

// somepage
console.log("loading file1");
yepnope([{ load: 'file1.js', callback: function () {
        console.log("loaded file1");
    }
}]);

// file1.js
console.log("loading file2");
yepnope([{ load: 'file2.js', callback: function () {
        console.log("loaded file2");
    }
}]);

// file2.js
console.log("finished");

Result:
loading file1
loading file2

And in firebug net panel, i see that both files have correctly been loaded, however the callbacks and console.log("finished") does not seem to fire.

IE not loading CSS file, link created but href set to "undefined"

Hi All,

I've a rather bizarre issue with yepnope (using Modernizr.load from a bespoke compilation of Modernizr 2) in which Internet Explorer 6, 7 & 8 will successfully download a Javascript file but not the accompanying CSS file.

Looking at the DOM within the IE Dev Toolbar, I can see that a LINK has been created and injected into the HEAD by yepnope but that it's HREF is set to "undefined".

Here's a testcase: http://www.frequency-decoder.com/demo/fd-slider/test/yepnope/

Note: Please excuse the alerts thrown at you by the testcase - they are just alerting the three arguments passed to the callback function (result, key and url). The problem persists even with the alert removed.

Here's the important bit of the Modernizr.load call:

test: Modernizr.inputtypes.range,
nope: ['/demo/fd-slider/test/css/fd-slider.min.css' ,'/demo/fd-slider/test/js/fd-slider.js']

Here's the Modernizr header:

/* Modernizr 2.0.4 (Custom Build) | MIT & BSD

  • Contains: input | inputtypes | iepp | respond | mq | cssclasses | teststyles | load
    */

Here's what I've looked into so far...

  1. The CSS file is being sent with the proper mime type (checked in Firebug) so this isn't the cause.
  2. Another page http://www.frequency-decoder.com/demo/fd-slider/test/ doesn't use Modernizr (.load) and the CSS file loads & renders correctly in IE.
  3. The original CSS file was rather large so I minified it thinking that filesize may be the issue. No Luck.
  4. I use MHTML in the CSS file - a lot. Thinking that this might be the cause, I stripped all of the comments & MHTML block from the file and tried again. Unfortunately, the problem still persists so the MHTML block doesn't seem to be the cause.

I haven't attempted using an older version of yepnope to see if I can replicate the problem using an older codebase.

The only other thing that I can do is start to remove CSS rules one by one to see if/when the file loads correctly.

Hopefully it's something stupid that I've completely overlooked (can't see the wood for the trees etc) - in fact, this is the first time in my life that I wish the problem was generated by my code and not someone else's.

I'm heading to London and won't be available to reply to questions until Monday. Apologies for that. Not very cool to post a github issue and then disappear from view for a few days.

Regards,
Brian

investigate other inferences than [moz|webkit]Appearance

i talked to tantek (who is the author of the appearance spec) about this and he's not terribly comfortable about script relying on those prefixed props being the way to detect browser..

however... he did admit there is no interop (except for the value of none) so standardizing and going unprefixed looks unlikely in the short term.

so it might be the lucky style prop that could stay prefixed for a while...

full convo: http://pastie.org/1432000

Yepnope hangs browser for 10-15 secs. when loading CSS from another host

This is strange. I'm updating my site to have static files on another subdomain (static.domain.com) vs. the non-static stuff (www.domain.com). I came across the weird situation where the browser (all that I've tried, Chrome 14, Safari 5, Firefox 6, all on Mac OS X) just pause in the middle of loading for 10-15 seconds.

Through a long process of elimination, I've boiled it down to loading a css file from the static.domain.com host via Modernizr.load. I move the reference to the HEAD of the document into a normal LINK element and boom, problem is gone. To doubly-verify this, I then made a super small test.css with one simple rule in, then tried to add that via Modernizr.load again, and the issue returned. (And the tiny file did successfully load.)

Has anyone else seen this?

Using Modernizr v2.0.6.

IE7 Error- "Internet Explorer cannot open the Internet site [url here]. Operation aborted"

Hello,

Like most people, I'm using a combination of things- HTML5 Boilerplate, Modernizr and YepNope. In IE7 when I load the page I'm getting an error dialog that says, "Internet Explorer cannot open the Internet site [url here]. Operation aborted". Once clicked, the browser crashes.

I've done my fair share of debugging and have found that when I invoke yepnope it comes crashing down. :( I've included a pastie of the source code and an url to the page in question:

http://pastie.org/1541287

http://benbabics.com/otr/

Any help is much appreciated.

Regards,
Ben Babics

Quick abort on 404

The yepnope.errorTimeout makes sense when waiting for files to load, but if the file doesn't exist there's no point in waiting for it. Since there isn't a way to check for file existence in js, trying to load a file that results in a 404 just makes the page hang for awhile. Seems there should be some option on how to handle different error types, especially 404.

Firefox wants to load plugins to handle application/json...

Hi,

Attempting to use yepnope to load a remote js (for twitter). The server responds with a MIME-type of "application/json". This works fine in most browsers, but in Firefox 3.6.1 (at least), the user is prompted to "Install Missing Plugins...". When I lazy load with jQuery, I don't have this issue.

I've tried creating a prefix 'js!' to force the type to JS, but it doesn't seem to have any affect. Here's some code to work with:

var twitterid = 'some_twitter_id';

yepnope.addPrefix('js', function (res) {
  res.forceJS = true;
  return res;
});
yepnope({
  test: window.twitterCallback2,
  nope: "js!http://twitter.com/javascripts/blogger.js",
  complete: function() {
    yepnope('js!http://twitter.com/statuses/user_timeline/' + twitterid +'.json?callback=twitterCallback2&count=3')
  }
});

This is the jQuery code that works fine:

if (!window.twitterCallback2) {
  $.getScript("http://twitter.com/javascripts/blogger.js", function() {
    $.getScript('http://twitter.com/statuses/user_timeline/' + twitterid +'.json?callback=twitterCallback2&count=3');
  });
}
else {
  $.getScript('http://twitter.com/statuses/user_timeline/' + twitterid +'.json?callback=twitterCallback2&count=3');
}

This doesn't cause the 'missing plugin' issues, but its not as DRY either. =(

CSS Cross-Domain loading in Chrome and Safari is broken

It seems Webkit always hit the 10-seconds timeout when loading a CSS-File from another Domain.

I guess the reason is, that in line 138 those browser won't fire a security-exception for link.sheet - the element is just empty.

I created Demos to help understanding the problem:

http://sellaround.efreetsystems.de/yepnope/bugDemo.html
http://sellaround.efreetsystems.de/yepnope/bugDemoFixed.html

NOTE: The interesting part here is the JS-Callback - the CSS applies of course as soon as it's loaded.

I created a patch which should fix this:

  138c138,139
  <               if ( link.sheet.cssRules.length )  {
  ---
  >               // Chrome won't throw a security or denied exception in case of same origin - cssRules will simply stay empty
  >               if ( (isWebkit && link.sheet !== null) || (isGecko && link.sheet.cssRules.length) ) {

I tested it with Safari 5.1 and Chrome 12.

Last but not least: Thank you for this great tool!

Issue with script type 'j'

In Firefox, currently yepnope seems to be loading the scripts in order, however there is no execution within the browser. By commenting out line 264 "preloadElem.type = type;", the internal string "j" or "c" is never passed and the script loads successfully. I haven't noticed this issue in Chrome/Safari, but am able to reproduce in Firefox. I can only surmise that Firefox is enforcing the script type attribute prior to browser execution, but I've been unable to verify.

Linked below is a screenshot of the test suite running locally(based on the master branch).

http://screencast.com/t/md25yTKX

Seperate yepnope calls result in Throbber/Spinner going forever in FF

Hello YepNopeJS Team,

Thanks for all of your hard work. It may be silly to begin with that, but I personally want to thank you for all of your hard work in putting together a great piece of functionality. :)

Anyways, I have YepNope loading the base scripts for my application and have passed in an object literal with complete to fire a callback. This will fire a call to a class I have written that triggers callbacks that have been collected for inline scripts (on page includes) that are dependent on the base scripts ( similar, but not as awesome as $.ready() ).

In this instance I have a page script that is needs to load one or more scripts, so I'm using YepNope again to load those additional scripts for that page. This works just fine, however, I have noticed that FireFox 3.6 continues to think it's still loading.

I have posted an example on my server: http://www.benbabics.com/otr/

Any help, or suggestions how to do otherwise are much appreciated.

Regards,
Ben Babics

Cannot fallback when some URLs are not accessible

My code:

yepnope([{ load: "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.2.min.js"
        , complete: function() {
            if (!window.jQuery) {
                yepnope('../javascript/jquery.min.js');
            }
        }
}, /* some resource */]);

MS's CDN is down and my local file has not be loaded.
I tested the code, the "if" block run but yepnope didn't load the file for me, the file is exist:

yepnope([{ load: "../javascript/jquery.min.js"}, /* some resource */]); // works!

How to force yepnope to execute some scripts immediately?

I have a few scripts loaded with yepnope:

Modernizr.load(['script1.js', 'script2.js']);

However, I also would like to use yepnope to load google analytics code:

Modernizr.load('http://www.google-analytics.com/ga.js');

How do I combine these two so that when script1.js and script2.js are downloaded, they execute immediately and don't wait for google analytics code to be downloaded.

I tried simply concat them, making two async calls together, and it doesn't seem to work.

Any ways to do that?

Thanks.

Add a way to specify parameters for scripts

Some scripts have to be loaded this way:

<script type="text/javascript" src="https://apis.google.com/js/plusone.js">
  {"parsetags": "explicit"}
</script>

I think that there is no way currently to do this with yepnope.

Single execution of script referenced more than once

Given two separate scripts that both use yepnope to conditionally load a shared library script, how can I ensure the referenced script is only executed once? Is yepnope able to track what it has already executed and not re-execute?

I'm looking to build yepnope support into my .net asset pipeline project: http://getcassette.net

Simple usage help.. test: is particular page?, yep: load script

Hi,
I've been looking for a way to only load certain js files for certain pages. I'm using a CMS to load my scripts and would like to just use the same block of code on every page to load certain script files depending on what page the user is currently on.

Is it possible to use yepnope to simply test if we are on a particular page and if so load particular script files? Is this even possible with yepnope?

For example I would like to do something like this:

test : body class='home',
yep : load 'home_scripts.js'

test : body class='contact',
yep : load 'contact_scripts.js'

Apologies if I've misunderstood what this script is used for! All the examples I can find test for particular features using modernizer but I can't find any that explain what I need..

Thanks for any advice

Loading JavaScript templates

For loading JS templates files written in jQuery.tmpl, underscore.js, eco, etc so we need a type property and code inlining:

<script type="text/template" src="helloworld.eco">template code</script>

JSON Test in IE 9

Using code similar to the function below, I am seeing IE 9 appear to download json2.js in the profiler. Why would IE 9 appear to download json2.js if window.JSON is available?

yepnope({
  test: window.JSON,
  nope: 'json2.js',
  complete: function () {
    // run some JavaScript!!!
  }
});

Double loading issue in Firefox

New case as the specific scenario in issue 10 may have been separate, but I apologize if this is a duplicate case. After removing the script type(as described in issue 14), I do observe the duplicate script issue. The script seems to be loaded twice as a resource, which doesn't necessarily offend me, but is also executing twice and producing some erratic behavior.

The locally run test suite on the master branch is linked below:

http://screencast.com/t/md25yTKX

CSS loading fails with unexpected token

Pretty new to yepnope, so I might be missing something really basic here.
I seem to be unable to load a css file from google fonts. The file is loaded but seems to fail on parsing, tripping on the very first '@' character on the file.

Error

Here is the javascript that generates the error.

yepnope('css!http://fonts.googleapis.com/css?family=Nova+Square&v1');

I've tested this on Chrome Stable, Chromium Dev, Firefox 5, Opera 11.50 on Ubuntu 11.04.

Google maps

Hi,

Seems like something wierd is going on when i try to load the google maps api,

try this :

        yepnope([{
            load: 'http://maps.google.com/maps/api/js?sensor=false',
            callback: function () {
                console.log('maps was loaded!');
            }
        }]);

Here this causes the page to get overwritten, like when you do a document.write.

Nice plugin btw!
Robert

Scripts prefixed with 'ie6!' are being loaded in every browser (I've tested).

Hi again. I'm using the following in my HTML:

<script>
  yepnope({
    load: [ 
      "/js/jquery-1.5+tinypubsub-0.6.min.js",
      "ie6!/js/dd-belated-png.min.js"
    ],
    complete : function() {
      // Delay loading until DOM READY signal
      jQuery(function(){ yepnope("/js/front.js"); });
    }
  });
</script>

And, in Chrome 10.0.648.11, Safari 5.0.3 and Firefox 3.6.15 (Mac), I'm seeing dd-belated-png.min.js IS loaded. Am I doing it wrong? I have double-checked, I do not load that script in any other way. And the fact that it is loaded is evident when I print "window.DD_belatedPNG" on the console, it returns the relevant object.

The good news is, it IS loading in IE 6 too. =)

Add Support for Functions

I'm completely onboard with the loading of files; however, there are times when a one-liner will suffice. For this, it would be awesome if we could pass in a function reference instead of a file name. For instance...

function pinHome(){ ... }
yepnope({ test:Modernizr.geolocation, yep:['map.js', pinHome] });

In addition to scenarios with short one-liners, this may also be beneficial for reuse in your main script, if you simply need to call a function in multiple places.

CSS files not being treated as CSS if querystring is attached

Was working on a presentation and need to make sure the CSS was not loading from cache and came account is this issue:

If I try to load a CSS file like so:

yepnope(
    {
        load : [
            "assets/js/lib/jquery.ui.core.js",
            "assets/js/lib/jquery.ui.widget.js",
            "assets/js/lib/jquery.ui.position.js",
            "css!assets/css/lib/jquery.ui.core.css?time=12121"
        ],
        callback : function (url, result, key) {},
        complete : function (){}
    }
);

The CSS file is being loaded via a script take and not a link tag. The same happens in either of the yep or nope options.

yepnope loading js into iframes in Firefox 3.6

I'm using yepnope on a site with ads that frequently serve content through iframes. I've noticed a bug in Firefox 3.6 where the script I am loading is loaded into the iframe replacing the ad content. So in place of the ad, you will see the javascript plain text.

load JSON with yepnode

hello, can you imagine the load JSON with yepnode?
In fact, I use some JSON file for translation of items and I usually loads getScript with jQuery
I seek the best way to get performance in terms of asynchronous loading for my CMS
Great project ;)
Best regards

JW flv Player swfobject.js loaded, but not found then

Is it possible to load the swfobject.js which is needed for the JW flv Player (http://www.longtailvideo.com) ) also inside yenope?

I have to load it outside with a normal <script src=> or it "SWFObect" is not found then in the scripts that build the movie players later in the body.

Sorry if I am too unprecise here, Im not experienced programmer.

What I did now is to load it inside yenope and than again outside in the head, seems to be faster than only outside.

Also I wonder how to load a script that has an artificial attribut as f.e. contentflow with load=

<script src=files/_layout/_js/ContentFlow/contentflow.js load=covers></script>

Because this script needs so much time, it would beneficial to be able to include into the yenope array.

Thank you for your amazing work -- Kai

Support fallbacks in `complete` and `callback`

Hi!

I did follow the fallback example for jQuery from the documentation but this does not work as expected. If the fallback happens, the jQuery object does not exist. Here is a simple test case :

<html class="no-js">
<head>
  <script src="SlexAxton-yepnope.js-7f0bef6/yepnope.1.0.2-min.js"></script>
</head>
<body>
  <script>
yepnope.errorTimeout = 1000;
yepnope([{
   load: '//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.miin.js',
   complete: function () {
       if (!window.jQuery) {
       yepnope('media/js/libs/jquery-1.6.1.min.js');
       }
   }
 },{
   load: 'test1.js',
   complete: function() { alert(jQuery) }
 }]);
  </script>
</body>
</html>

Notice the typo in the Google Ajax to force the fallback. On Chromium 12.0.742, jQuery is undefined despite the fact that local jquery is loaded. On Firefox 5, the local version is not even loaded! test1.js is just an empty file.

Final complete?

Hi,

I wondered if there's anything like a "final" complete to be used when multiple loads are attempted. For example, something like:

  // Try to load the jQuery and jQuery UI libraries
  yepnope([
  {

    // Load the jQuery library from Google's AJAX API CDN
    load: 'https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js',

    // Determine if the local copy of the jQuery library needs to be loaded
    callback: function()
    {

      // If the jQuery library could not be loaded then load the local copy
      if (!window.jQuery)
      {
        yepnope('includes/js/jquery.min.js');
      }

    }

  }, {

    // Load the jQuery UI library from Google's AJAX API CDN
    load: 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js',

    // Determine if the local copy of the jQuery UI library needs to be loaded
    callback: function()
    {

      // If the jQuery UI library could not be loaded then load the local copy
      if (!window.jQuery.ui)
      {
        yepnope('includes/js/jquery-ui.min.js');
      }

    }

  }, {

    // Include the main body of javascript
    complete: function()
    {
      $('#wrapper').show();
    }

  }
  ]);

I don't want to try to run the "main body" of javascript until the depended libraries have been loaded.

Thanks.

Support media attribute when loading CSS

yepnope doesn't support setting the media attribute for lazy-loading CSS. It would be very useful to have this support (e.g. loading stylesheets for print, handheld, etc.)

Downloaded bundle missing files ?

I downloaded latest 1.0.2 archive, and runnig demo: demo/index.html
There are script src="../filters/yepnope.autoprotocol.js" line in header,
but actually there are no file named "filters/yepnope.autoprotocol.js" in the bundle.

Is it necessary ?

It not working for me in mozilla FireFox. (windows platform)

I run tests -
It does not passed all test on latest builds of Mozilla Firefox (8.0), here is screenshot:
http://bm.galaxyhost.org/_rs/capt/20110828-54g-93kb.jpg

Than I test it on stable (version 6.0) too, the results is the same:
http://bm.galaxyhost.org/_rs/capt/20110828-1tf-90kb.jpg

Opera 9 issue?

Me again =)

  yepnope({
    load: [ 
      "/js/jquery-1.5+tinypubsub-0.6.min.js"
    ],
    complete : function() {
      jQuery(function(){ yepnope("/js/front.min.js"); });
    }
  });

In Opera 9, I get 'jQuery is not defined'. Works well in other browsers.

Small JS files fail to load in FF 7.0.1

In FF small scripts are fetched but are not executed. Quick investigation showed that preloadElem.onload is not fired.
See below for a reproduction case:

nope.html

<html>
    <head>
        <script src="yepnope-1.0.2.js" type="text/javascript"> </script>
        <script type="text/javascript">
            setTimeout(function(){yepnope({
                        load: 'test.js',
                        complete: function() {
                            foo();
                        }
            });}, 0);
        </script>
    </head>
    <body></body>
</html>

test.js

alert('this is test.js');

function foo() {
    alert('this is foo()');
}

Add ability to prevent preloading for scripts that shouldn't be cached

It would be nice to use yepnope to load js that deliver data that shouldn't be cached. For example, Google's local search json api: http://code.google.com/apis/maps/documentation/localsearch/jsondevguide.html#json_reference

Their scripts are never sent with headers that tell the browser to cache the response.

Example Headers from their api:
Cache-Control:no-cache, no-store, max-age=0, must-revalidate
Content-Encoding:gzip
Content-Length:1649
Content-Type:text/javascript; charset=utf-8
Date:Tue, 08 Mar 2011 22:48:29 GMT
Expires:Fri, 01 Jan 1990 00:00:00 GMT
Pragma:no-cache
Server:GSE
X-Content-Type-Options:nosniff
X-Embedded-Status:200
X-Frame-Options:SAMEORIGIN
X-Xss-Protection:1; mode=block

This causes two assets to be dealt with by the browser: http://grab.by/grabs/9ace492b8ebd253039cadcac32c11551.png

I read through the prefix and yepnope source in an effort to try to write my own "nocache!" prefix, but it looks like the preloading is pretty integrated.

firstScript.parentNode is NULL due to other ajax calls on the page

Hi,

first thing: awesome tool :)

Here is my issue

Scenario: I am introducing the use of yepnope in existing sites, slowly migrating newly created scripts into libraries that can be loaded asynchronously. For this reason, there are scripts that need to work synchronously and dependencies that have to be loaded outside of yepnope. Also, I do not have the option of making sure that the reference to yepnope is the first script to be executed on the page.

Problem: one of the pages I am testing has a jQuery.getScript call before my yepnope script reference. This is what happens:

  1. The jQuery.getScript creates a script tag as first child of the head tag and starts the async call
  2. Yepnope initializes, savings the script tag created by jquery as the "firstScript" variable
  3. Yepnope starts preloading the javascript files as per commands
  4. The jQuery call completes and script tag gets removed from the DOM by the event handler within the jquery code
  5. Yepnope is ready to execute the loaded scripts, but now the "firstScript" variable points to an element that has been removed from the DOM, therefore with parentNode equal to NULL. This makes the firstScript.parentNode.insertBefore(script, firstScript) [line 111] call throw an exception

One proposed solution could be (like jQuery does) to use the head element directly, without pre-saving another script tag that can potentially be removed from the document: head.insertBefore(script, head.firstChild)

Thanks

Rob

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.