2 Catalyst::Plugin::Static::Simple - Make serving static pages painless.
6 MyApp->setup( qw/Static::Simple/ );
9 The Static::Simple plugin is designed to make serving static content in
10 your application during development quick and easy, without requiring a
11 single line of code from you.
13 It will detect static files used in your application by looking for file
14 extensions in the URI. By default, you can simply load this plugin and
15 it will immediately begin serving your static files with the correct
16 MIME type. The light-weight MIME::Types module is used to map file
17 extensions to IANA-registered MIME types.
19 Note that actions mapped to paths using periods (.) will still operate
22 You may further tweak the operation by adding configuration options,
25 ADVANCED CONFIGURATION
26 Configuration is completely optional and is specified within
27 MyApp->config->{static}. If you use any of these options, the module
28 will probably feel less "simple" to you!
30 Forcing directories into static mode
31 Define a list of top-level directories beneath your 'root' directory
32 that should always be served in static mode. Regular expressions may be
35 MyApp->config->{static}->{dirs} = [
40 Including additional directories (experimental!)
41 You may specify a list of directories in which to search for your static
42 files. The directories will be searched in order and will return the
43 first file found. Note that your root directory is not automatically
44 added to the search path when you specify an include_path. You should
45 use MyApp->config->{root} to add it.
47 MyApp->config->{static}->{include_path} = [
53 With the above setting, a request for the file /images/logo.jpg will
54 search for the following files, returning the first one found:
56 /path/to/overlay/images/logo.jpg
57 /dynamic/path/images/logo.jpg
58 /your/app/home/root/images/logo.jpg
60 The include path can contain a subroutine reference to dynamically
61 return a list of available directories. This method will receive the $c
62 object as a parameter and should return a reference to a list of
63 directories. Errors can be reported using die(). This method will be
64 called every time a file is requested that appears to be a static file
65 (i.e. it has an extension).
69 sub incpath_generator {
72 if ( $c->session->{customer_dir} ) {
73 return [ $c->session->{customer_dir} ];
75 die "No customer dir defined.";
80 To override or add to the default MIME types set by the MIME::Types
81 module, you may enter your own extension to MIME type mapping.
83 MyApp->config->{static}->{mime_types} = {
88 Apache integration and performance
89 Optionally, when running under mod_perl, Static::Simple can return
90 DECLINED on static files to allow Apache to serve the file. A check is
91 first done to make sure that Apache's DocumentRoot matches your Catalyst
92 root, and that you are not using any custom MIME types or multiple
93 roots. To enable the Apache support, you can set the following option.
95 MyApp->config->{static}->{use_apache} = 1;
97 By default this option is disabled because after several benchmarks it
98 appears that just serving the file from Catalyst is the better option.
99 On a 3K file, Catalyst appears to be around 25% faster, and is 42%
100 faster on a 10K file. My benchmarking was done using the following
101 'siege' command, so other benchmarks would be welcome!
103 siege -u http://server/static/css/10K.css -b -t 1M -c 1
105 For best static performance, you should still serve your static files
106 directly from Apache by defining a Location block similar to the
110 SetHandler default-handler
113 Bypassing other plugins
114 This plugin checks for a static file in the prepare_action stage. If the
115 request is for a static file, it will bypass all remaining
116 prepare_action steps. This means that by placing Static::Simple before
117 all other plugins, they will not execute when a static file is found.
118 This can be helpful by skipping session cookie checks for example. Or,
119 if you want some plugins to run even on static files, list them before
122 Currently, work done by plugins in any other prepare method will execute
125 Debugging information
126 Enable additional debugging information printed in the Catalyst log.
127 This is automatically enabled when running Catalyst in -Debug mode.
129 MyApp->config->{static}->{debug} = 1;
132 Catalyst, Catalyst::Plugin::Static,
133 <http://www.iana.org/assignments/media-types/>
136 Andy Grundman, <andy@hybridized.org>
139 The authors of Catalyst::Plugin::Static:
145 For the include_path code from Template Toolkit:
150 This program is free software, you can redistribute it and/or modify it
151 under the same terms as Perl itself.