NAME

Mojolicious::Plugin::JSLoader - move js loading to the end of the document

VERSION

version 0.01

SYNOPSIS

In your startup:

  sub startup {
      my $self = shift;

      # do some Mojolicious stuff
      $self->plugin( 'JSLoader' );

      # more Mojolicious stuff
  }

In your template:

<% js_load('js_file.js') %>

HELPERS

This plugin adds a helper method to your web application:

js_load

This method requires at least one parameter: The path to the JavaScript file to load. An optional second parameter is the configuration. You can switch off the base for this JavaScript file this way:

# <script type="text/javascript" src="$base/js_file.js"></script>
<% js_load('js_file.js') %>

# <script type="text/javascript" src="http://domain/js_file.js"></script>
<% js_load('http://domain/js_file.js', {no_base => 1});

HOOKS

When you use this module, a hook for after_render is installed. That hook inserts the <script> tag at the end of the document or right before the closing <body> tag.

METHODS

register

Called when registering the plugin. On creation, the plugin accepts a hashref to configure the plugin.

# load plugin, alerts are dismissable by default
$self->plugin( 'JSLoader' );

Configuration

$self->plugin( 'JSLoader' => {
    base => 'http://domain/js',  # base for all <script> tags
});

NOTES

This plugin uses the stash key __JSLOADERFILES__, so you should avoid using this stash key for your own purposes.

AUTHOR

Renee Baecker <reneeb@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2013 by Renee Baecker.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)