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";

Local assets

Here is the basic way of defining an asset:

    "some-asset.js" => (

The "some-asset.js" string is just so you can refer to the generated bundle in your templates later, while the list of files after (foo.js and bar.js) are files that exist in one of the public static directories defined in your application.

Online assets

The assets do not need to be on the same machine. They can also be fetched from the world wide web:

    "bundle.js" => (

The code above 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.

Dynamic assets

This is very similar to "Online assets", except that they are generated by the current Mojolicious application.

  app->asset("some-asset.js" => "/dynamic-path/foo.css")

The above "/dynamic-path/foo.css" will be fetched from the current app unless a static file has the same name.


Now that you know how to define your assets, you can start using them in your templates.


Jan Henning Thorsen -