Catalyst Advent - Day 23 - Static::Simple


Static::Simple is a plugin that will help to serve static content for your application. By default, it will serve most types of files, excluding some standard Template Toolkit extensions, out of your root file directory. All files are served by path, so if images/me.jpg is requested, then root/images/me.jpg is found and served.


Using the plugin is as simple as setting your use line in to:

 use Catalyst qw/Static::Simple/;

and already files will be served.


Include Path

You may of course want to change the default locations, and make Static::Simple look somewhere else, this is as easy as:

 MyApp->config->{static}->{include_path} = [

When you override include_path, it will not automatically append the normal root path, so you need to add it yourself if you still want it. These will be searched in order given, and the first matching file served.

Static directories

If you want to force some directories to be only static, you can set them using paths relative to the root dir, or regular expressions:

 MyApp->config->{static}->{dirs} = [

File extensions

By default, the following extensions are not served: tmpl, tt, tt2, html, xhtml. This list can be replaced easily:

 MyApp->config->{static}->{ignore_extensions} = [
    qw/tmpl tt tt2 html xhtml/ 

Ignoring directories

Entire directories can be ignored. If used with include_path, directories relative to the include_path dirs will also be ignored:

 MyApp->config->{static}->{ignore_dirs} = [ qw/tmpl css/ ];

More information