Javascript Queue Sprint plugin

Plugin details

JSQueueSpring is a wee lightweight library written by William Harding (http://www.williambharding.com/blog) that handles declaring JS midpage and rendering it at the bottom of the page. The benefits of outputting JS at the bottom of your web page are well chronicled on the web (one reason: render first, run JS later means page load times appearing faster).

Websitehttp://www.williambharding.com/blog/rails/rails-plugin-javascript-unqueue-spring-all-javascript-output-at-page-bottom/ Repositoryhttp://jsqueuespring.googlecode.com/svn/trunk/js_queue_spring/ Author Bill Harding Tags Javascript, query LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install http://jsqueuespring.googlecode.com/svn/trunk/js_queue_spring/

Standard usage... executes JS page after page has loaded, similar to javascript_tag:

<% queue_js do 
	<< -STRING
		alert('Here I am, loading when the page is done.');
	STRING
end %>


Would wrap the alert in tags (and the CDATA crap), and then execute it when the page was done loading.
Note that you can (obviously?) call queue_js as many times as you like. The call will queue all JS until unqueue_js is called (which automatically happens at the end of any render call)

Alternately, you can also use pass :flat as a parameter to queue_js if you don't want your JS to automatically be executed, i.e.,

<% queue_js(:flat) do
	<< -STRING
	function someLocalFunction() {
		alert("I won't be executed until somebody calls me");
	}
	STRING
end %> 


All JS queued with the flat parameter will be added to the page before JS that will execute, so you can declare functions in the :flat areas that are called in the executed areas.

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | Back in time (2 older versions) | Last edited by: hardway, 4 months ago