- CONFIG PARAMS
- SEE ALSO
- COPYRIGHT AND LICENSE
Catalyst::Controller::AutoAssets - Automatic asset serving via sha1-based URLs
In your controller:
package MyApp::Controller::Assets::MyCSS; use parent 'Catalyst::Controller::AutoAssets'; 1;
Then, in your .conf:
<Controller::Assets::MyCSS> include root/my_stylesheets/ type css minify 1 </Controller::Assets::MyCSS>
And in your .tt files:
<head> <link rel="stylesheet" type="text/css" href="[% c.controller('Assets::MyCSS').asset_path %]" /> </head>
Or, in static HTML:
<head> <link rel="stylesheet" type="text/css" href="/assets/mycss/current.css" /> </head>
Required - The asset type:
directory asset type works in a similar manner as Static::Simple to make some directory structure accessible at a public URL. The root of the structure is made available at the URL path:
MIME::Types is used to set the
Content-Type HTTP header based on the file extension (same as Static::Simple does).
Because the sha1 checksum changes automatically and is unknown in advance, the above Asset Path is made available via the
asset_path() controller method for use in TT files and throughout the application.
js types serve one automatically generated text file that is concatenated and optionally minified from the include files. The single, generated file is made available at the URL Path:
<CONTROLLER_PATH>/<SHA1>.js # for 'js' type <CONTROLLER_PATH>/<SHA1>.css # for 'css' type
Required - String or ArrayRef. The path(s) on the local filesystem containing the source asset files. For
directory type this must be exactly one directory, while for
js it can be a list of directories. The
include directory becomes the root of the files hosted as-is for the
directory type, while for
js asset types it is the include files concatinated together (and possibly minified) to be served as the single file.
Whether or not to make the current asset available via 307 redirect to the real, current checksum/fingerprint asset path. This is a pure HTTP mechanism of resolving the asset path.
<CONTROLLER_PATH>/current/ # for 'directory' type <CONTROLLER_PATH>/current.js # for 'js' type <CONTROLLER_PATH>/current.css # for 'css' type
For instance, you might reference a CSS file from a
Controller::Assets::ExtJS using this URL path (i.e. href in an HTML
This path would redirect (HTTP 307) to the current asset/file path which would be something like:
The downside of this is that the server has to serve the non-cachable redirect every time, which partially defeats the performance benefits of this module (although the redirect is comparatively lightweight).
The other mechanism to find the current asset path is via the
asset_path() method, which returns the current path outright and is the recommended usage, but is only available in locations where application controller methods can be called (like in TT files).
Defaults to true (1).
Alias to use for the
current_redirect. Defaults to 'current' (which also implies 'current.js'/'current.css' for
css asset types).
Whether or not to attempt to minify content for
js asset types. This is a purely optional convenience feature.
Defaults to false (0). Does not apply to the
directory asset type.
CodeRef used to minify the content when
minify is true. The default code is a pass-through to
css assets and
js. If you want to override you must follow the same API as in those modules, using the
Does not apply to the
directory asset type.
The directory where asset-specific files are generated and stored. This contains the checksum/fingerprint file, the lock file, and the built file. In the case of
directory assets the built file contains a manifest of files and in the case of
js assets it contains the actual asset content (concatenated and possibly minified)
Number of seconds to wait to obtain an exclusive lock when recalculating/regenerating. For thread-safety, when the system needs to regenerate the asset (fingerprint and built file) it obtains an exclusive lock on the lockfile in the work_dir. If another thread/process already has a lock, the system will wait for up to
max_lock_wait seconds before giving up and throwing an exception.
Note that this is only relevant when the source/include content changes while the app is running (which should never happen in a production environment).
Defaults to 120 seconds.
Max number of seconds before recalculating the fingerprint of the content (sha1 checksum) regardless of whether or not the mtime has changed. 0 means infinite/disabled.
For performance, once the system has calculated the checksum of the asset content it caches the mtime of the include file(s) and verifies on each request to see if they have changed. If they have, it regenerates the asset on the fly (recalculates the checksum and concatenates and minifies (if enabled) for
js asset types). If
max_fingerprint_calc_age is set to a non-zero value, it will force the system to regenerate at least every N seconds regardless of the mtime. This would only be needed in cases where you are worried the content could change without changing the mtime which shouldn't be needed in most cases.
Defaults to 0.
The content type returned in the 'Content-Type' header. Defaults to
js types respectively.
Does not apply to
directory asset type. For files within
directory type assets, the Content-Type is set according to the file extension using MIME::Types.
'Cache-Control' header to return when serving assets. Defaults to the maximum aggressive value that should be honored by most browsers (1 year):
public, max-age=31536000, s-max-age=31536000
Returns true (1) if the asset type is
directory and false (0) if the type is
Returns the current, public URL path to the asset:
<CONTROLLER_PATH>/<SHA1> # for 'directory' type <CONTROLLER_PATH>/<SHA1>.js # for 'js' type <CONTROLLER_PATH>/<SHA1>.css # for 'css' type
directory asset types, accepts an optional subpath argument to a specific file. For example, if there was a file
images/logo.gif within the include directory, $c->controller('Foo::MyAsset')->asset_path('images/logo.gif') might return:
Henry Van Styn <email@example.com>
This software is copyright (c) 2013 by IntelliTree Solutions llc.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 703:
=back without =over