Giter Club home page Giter Club logo

javascript-on-demand's Introduction

[3.0.4] Javascript On Demand with HeadJS

Checkout index.html with this example bellow.

  1. We depend of HeadJS library to to do our magic, so add it and out function just into head of your html.
	<script src="assets/vendor/headjs/dist/1.0.0/head.load.min.js"></script>
	<script src="lib/app.js"></script>
  1. After it, you nee to create an instance of the App function.

The App function can receive the following params during its instantiation:

var app = {
  protocol : "",
  host : "localhost",
  // You can define default instances or vendors to load in every page filling this next parameters
  instances : [],
  vendors : []
};
 
3. In each page of your site, you can define those scripts to load or call by instances, like this:

>Instance will run after each vendor defined on current page.
```javascript
app.setInstances([
   "myMenuPlugin();",
   "AnotherFormValidation();"
]);
 
app.setVendors([
   'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js'
]);

each vendor entry URL, if it isn't a valid URL, is adjusted to a complete URL, so 'assets/js/main.js' will be transformed to 'http://localhost/assets/js/main.js'

  1. At least, if you have a footer that repeats in everything, put it there just before the </body>.

This code will load every instance and vendor that you had set.

if (typeof head === 'function' && typeof App === 'function' && typeof app !== 'undefined') {
	head.load(app.getVendors(), function() {
		console.table(app.getVendors());
	});
}

javascript-on-demand's People

Contributors

marcosfreitas avatar

Stargazers

 avatar

Watchers

 avatar  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.