Configuration options ===================== .. py:module:: fanstatic Fanstatic makes available a number of configuration options. These can be passed to the :py:class:`Fanstatic` WSGI component as keyword arguments. They can also be configured using `Paste Deploy`_ configuration patterns (see :doc:`our Paste Deploy documentation ` for more information on that). .. _`Paste Deploy`: http://pythonpaste.org/deploy/ versioning ---------- If you turn on versioning, Fanstatic will automatically include a version identifier in the resource URLs it generates and injects into web pages. This means that for each version of your Javascript resource its URL will be unique. The Fanstatic publisher will set cache headers for versioned resource URLs so that they will be cached forever by web browsers and caching proxies [#well]_. By default, versioning is disabled, because it needs some extra explanation. We highly recommend you to enable it however, as the performance benefits are potentially huge and it's usually entirely safe to do so. See also ``recompute_hashes`` if you want to use versioning during development. The benefit of versioning is that all resources will be cached forever by web browsers. This means that a web browser will never talk to the server to request a resource again once it retrieved it once, as long as it is still in its cache. This puts less load on your web application: it only needs to publish the resource once for a user, as long as the resource remains in that user's cache. If you use a server-side cache such as Squid or Varnish, the situation is even better: these will hold on to the cached resources as well, meaning that your web application needs to serve the resource exactly *once*. The cache will serve them after that. But what if you change a resource? Won't users now get the wrong, old versions of the changed resource? No: with versioning enabled, when you change a resource, a *new* URL to that resource will be automatically generated. You never will have to instruct users of your web application to do a "shift-reload" to force all resources to reload -- the browser will see the resource URL has changed and will automatically load a new one. How does this work? There are two schemes: explicit versioning and an automatically calculated hash-based versioning. An explicit version looks like this (from the ``js.jquery`` package):: /fanstatic/jquery/:version:1.4.4/jquery.js A hash-based version looks like this:: /fanstatic/my_library/:version:d41d8cd98f00b204e9800998ecf8427e/my_resource.js The version of Resource depends on the version of the python package in which the Library is defined: it takes the explicit version information from this. If no version information can be found or if the python package is installed in `development mode`_, we still want to be able to create a unique version that changes whenever the content of the resources changes. To this end, the most recent modification time from the files and directories in the Library directory is taken. Whenever you make any changes to a resource in the library, the hash version will be automatically recalculated. The benefit of calculating a hash for the Library directory is that resource URLs change when a referenced resource changes; If resource A (i.e. ``logo.png``) in a library that is referenced by resource B (i.e. ``style.css``) changes, the URL for resource A changes, not because A changed, but because the contents of the library to which A and B belong has changed. Fanstatic also provides an MD5-based algorithm for the Library version calculation. This algorithm is slower, but you may use if you don't trust your filesystem. Use it through the ``versioning_use_md5`` parameter. .. _`development mode`: http://peak.telecommunity.com/DevCenter/setuptools#develop recompute_hashes ---------------- If you enable ``versioning``, Fanstatic will automatically calculate a resource hash for each of the resource directories for which no version is found. During development you want the hashes to be recalculated each time you make a change, without having to restart the application all the time, and having a little performance impact is no problem. The default behavior is to recompute hashes for every request. Calculating a resource hash is a relatively expensive operation, and in production you want Fanstatic to calculate the resource hash only once per library, by setting ``recompute_hashes`` to false. Hashes will then only be recalculated after you restart the application. bottom ------ While CSS resources can only be included in the ```` section of a web page, Javascript resources can be included in ``