Giter VIP home page Giter VIP logo

yepnope.js's Introduction

#yepnope.js#

A Conditional Script Loader For Your Polyfills, or Regressive Enhancement With Style.

A small script loader to help use feature detection to load exactly the scripts that your user needs, not just all the scripts that you think they might need.

More docs, etc at: http://yepnopejs.com

By:

Alex Sexton - AlexSexton [at] gmail

Ralph Holzmann - RalphHolzmann [at] gmail

Follow: @SlexAxton and @ralphholzmann on Twitter for more updates.

##A simple example (assuming modernizr is there):##

yepnope([
  {
    test : Modernizr.indexeddb,
    yep  : ['/js/indexeddb-wrapper.js', '/css/coolbrowser.css'],
    nope : ['/js/polyfills/lawnchair.js', '/js/cookies.js', '/css/oldbrowser.css']
  }
]);

##A crazy/contrived example:##

yepnope([
  // straight up load (using a force css prefix)
  'css!http://yayquery.com/css/base.css?alwaysload',
  
  // no tests, just a load and a callback
  {
    load:'http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js',
    callback: function(){
      console.log('jQuery was loaded!');
      window.oldalert = window.alert;
      window.alert = function(){};
    }
  },
  
  // conditional test based loading, with a default load
  {
    // The test
    test: Modernizr.csstransforms && Modernizr.csstransforms3d,
    
    // If it passes, 'yep' is completely optional, so let's not load anything...
    
    // If it fails
    nope: [
      'http://github.com/madrobby/vapor.js/raw/master/vapor.min.js',
      'css!http://yayquery.com/css/base.css?supports3d=false' //prefix with css! if it doesn't end in .css
    ],
    
    // Load it no matter what
    both: 'http://www.json.org/json2.js',
    
    // For each thing loaded
    callback: {
      'json2.js' : function() {
        window.alert = window.oldalert;
        console.log('bypassed crock\'s alert in json2 yo, because the test result was: ', testResult);
      }
    }
  }
]);

Any forks and stuff are welcome.

##Current Released Version##

1.0.1

NOTE: the code in the github repository is considered in development. Use at your own risk. The download buttons will link to our current release version.

##License##

All of the yepnope specific code is under the WTFPL license. Which means it's also MIT and BSD (or anything you want). However, the inspired works are subject to their own licenses.

##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/)[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.

Paul Irish - Thanks or whatever.

yepnope.js's People

Contributors

slexaxton avatar davidpadbury avatar

Stargazers

Vitalii avatar

Watchers

Vitalii avatar James Cloos avatar

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.