Go to page content

resource_lib

Serve css, javascript and simple images.

This Webmachine resource is used to serve files and images, especially ones in the lib folders of modules.

Multiple files can be served at once by combining them in one single request. See the {% lib %} tag for more information.  Javascript files are concatenated with a semi-colon and newline, all other files are concatenated with a newline character between the files.

This resource serves all files with a very long client side caching time. It also handles if-modifies-since checks. And it compresses served files with gzip when the user-agent supports it.

When serving multiple files then the modified response header will be set to the modification date of the newest file.

Example dispatch rule:

{lib, ["lib", '*'], resource_lib, []}

Resource_file_readonly has the following dispatch options:

OptionDescriptionExample
rootList of root directories where files are located. Use 'lib' for the library files. This defaults to the lib directory.{root, ["/var/www/css/"]}
content_dispositionIf the file should be viewed in the browser or downloaded. Possible values are inline and attachment. Defaults to the browser’s defaults by not setting the “Content-Disposition” response header.{content_disposition, inline}
use_cacheUse server side caching of files. Especially useful when gzip-compressing files or serving many combined css or javascript files. Less useful when a proxy cache like Varnish is used. Defaults to false.{use_cache, true}

Resource_lib does not handles any query arguments other than the file path.

This page is part of the Zotonic documentation, which is licensed under the Apache License 2.0.