Mojolicious::Plugin::AssetPack::Manual::Assets - How to define assets
This manual will show you various ways to define assets with Mojolicious::Plugin::AssetPack.
First you need to load the plugin. Here is an example lite app, which does that:
plugin "AssetPack";
Here is the basic way of defining an asset:
app->asset( "some-asset.js" => ( "/js/foo.js", "/js/bar.js", ) );
The "some-asset.js" string is just so you can refere to the genrated bundle in your templates later, while the list of files after (foo.js and bar.js) are files that exists in one of the public static directories defined in your application.
The assets does not need to be locally. They can also be fetched online:
app->asset( "bundle.js" => ( "http://cdnjs.cloudflare.com/ajax/libs/es5-shim/2.3.0/es5-shim.js", "http://cdnjs.cloudflare.com/ajax/libs/es5-shim/2.3.0/es5-sham.js", "http://code.jquery.com/jquery-1.11.0.js", "/js/myapp.js", ) );
The code aboove will download three assets from web and combine them with one asset defined locally.
NOTE! The online assets are cached locally, which means that they will not be refreshed, unless you manually delete them.
Now that you know how to define your assets, you can start using them in your templates.
Jan Henning Thorsen - jhthorsen@cpan.org
jhthorsen@cpan.org
To install Mojolicious::Plugin::AssetPack, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::AssetPack
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::AssetPack
For more information on module installation, please visit the detailed CPAN module installation guide.