Skip to content

abdalrahman-ahmed/getJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

getJS

A simple function for loading JS & CSS files asynchronously

  • Licensed MIT

Usage

Place the getJS function inline in the head of your page (it can also be included in an external JavaScript file if preferable).

Then call it by passing it a JavaScript URL:

<head>
	...
	<!-- include getJS here... -->
	<script src="getJS.js"></script>
	<!-- just example... -->
	<script>
		getJS( url, callback );
	</script>
	...
</head>

Examples

Load a single file with getJS:

getJS( "/path/to/script.js" );

You can execute code after the File has loaded via a callback:

getJS( "/path/to/script.js", function() {
	// The file has loaded
});

You can load multi files via Array:

// Example Without Callback!
getJS( ["/path/to/script.js","/path/to/style.css",...] );

// Example With Callback!
getJS( [
	"https://code.jquery.com/jquery-latest.min.js",
	"/path/to/script.js",
	"/path/to/style.css",
	"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css",
	...
], function() {
	// All files has loaded
});

Notice

getJS Will automatically added hostname location.origin if not find it in path.

Example:
getJS( "/javascript/script.js" );

This file will append to <head> like <script src="http://localhost/javascript/script.js" async></script>

About

A simple function for loading JS & CSS files asynchronously

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors