|
| 1 | +Handling of External Javascript and CSS Components |
| 2 | +================================================== |
| 3 | + |
| 4 | +This directory (``static/``) holds a number of subdirectories, where one is handled |
| 5 | +differently than the rest: the ``lib/`` subdirectory holds distribution files for external |
| 6 | +client-side components, currently (18 Apr 2015) this means ``js`` and ``css`` components. |
| 7 | + |
| 8 | +These components each reside in their own subdirectory, which is named with the component |
| 9 | +name: |
| 10 | + |
| 11 | + henrik@zinfandel $ ls -l static/lib |
| 12 | + total 44 |
| 13 | + drwxr-xr-x 6 henrik henrik 4096 Jul 25 15:25 bootstrap |
| 14 | + drwxr-xr-x 4 henrik henrik 4096 Jul 25 15:25 bootstrap-datepicker |
| 15 | + drwxr-xr-x 4 henrik henrik 4096 Jul 25 15:25 font-awesome |
| 16 | + drwxr-xr-x 2 henrik henrik 4096 Jul 25 15:25 jquery |
| 17 | + drwxr-xr-x 2 henrik henrik 4096 Jul 25 15:25 jquery.cookie |
| 18 | + drwxr-xr-x 2 henrik henrik 4096 Jul 25 15:24 ptmono |
| 19 | + drwxr-xr-x 2 henrik henrik 4096 Jul 25 15:24 ptsans |
| 20 | + drwxr-xr-x 2 henrik henrik 4096 Jul 25 15:24 ptserif |
| 21 | + drwxr-xr-x 2 henrik henrik 4096 Jul 25 15:25 select2 |
| 22 | + drwxr-xr-x 2 henrik henrik 4096 Jul 25 15:25 select2-bootstrap-css |
| 23 | + |
| 24 | +If resources served over a CDN and/or with a high max-age don't have different URLs for |
| 25 | +different versions, then any component upgrade which is accompanied by a change in template |
| 26 | +functionality will be have a long transition time during which the new pages are served with |
| 27 | +old components, with possible breakage. We want to avoid this. |
| 28 | + |
| 29 | +The intention is that after a release has been checked out, but before it is deployed, |
| 30 | +the whole static directory should be copied to a location which is accessible under the |
| 31 | +URL given by STATIC_URL -- in production mode this URL contains the datatracker release |
| 32 | +version, which will let the CDN serve the static files which correspond to the current |
| 33 | +release. |
| 34 | + |
| 35 | +With the exception of the ``pt*`` fonts, all components under ``static/lib/`` are managed |
| 36 | +through a bower_ file; ``ietf/static/bower.json``. In order to install a new |
| 37 | +version of a component, you should update the ``bower.json`` file, and then run the management |
| 38 | +command:: |
| 39 | + |
| 40 | + $ ietf/manage.py bower_install |
| 41 | + |
| 42 | +That command will fetch the required version of each external component listed in |
| 43 | +``bower.json`` (actually, it will do this for *all* ``bower.json`` files found in the |
| 44 | +``static/`` directories of all ``INSTALLED_APPS``), saving them temporarily under |
| 45 | +``.tmp/bower_components/``; it will then extract the relevant ``js`` and ``css`` files and |
| 46 | +place them in an appropriately named directory under ``static/lib/``. The location |
| 47 | +used by ``bower_install`` is is controlled by ``COMPONENT_ROOT`` in ``settings.py``. |
| 48 | + |
| 49 | +Any datatracker-specific static files which should be served by the CDN rather than |
| 50 | +directly by the datatracker web server should be moved from under ``static/ to ``ietf/static/``, |
| 51 | +so that they will be collected by the ``ietf/manage.py collectstatic`` command and |
| 52 | +placed under `static/lib/`` from where they will be made available to the CDN. Any |
| 53 | +template files referencing the files in question will need to be updated to use the |
| 54 | +``{% static 'foo/bar.jpg' %}`` notation to reference the files, so that the correct |
| 55 | +static url will be emitted. |
| 56 | + |
| 57 | +.. _bower: http://bower.io/ |
0 commit comments