1 @title Adding New CSS and JS
4 Explains how to add new CSS and JS files to Phabricator.
8 Phabricator uses a system called **Celerity** to manage static resources. If you
9 are a current or former Facebook employee, Celerity is based on the Haste system
10 used at Facebook and generally behaves similarly.
12 This document is intended for Phabricator developers and contributors. This
13 process will not work correctly for third-party code, plugins, or extensions.
17 To add a new CSS or JS file, create it in an appropriate location in
18 `webroot/rsrc/css/` or `webroot/rsrc/js/` inside your `phabricator/`
21 Each file must `@provides` itself as a component, declared in a header comment:
25 * @provides duck-styles-css
32 Note that this comment must be a Javadoc-style comment, not just any comment.
34 If your component depends on other components (which is common in JS but
35 rare and inadvisable in CSS), declare then with `@requires`:
39 * @requires javelin-stratcom
44 * Put class documentation here, NOT in the header block.
50 Then rebuild the Celerity map (see the next section).
52 = Changing an Existing File =
54 When you add, move or remove a file, or change the contents of existing JS or
55 CSS file, you should rebuild the Celerity map:
57 phabricator/ $ ./bin/celerity map
59 If you've only changed file content things will generally work even if you
60 don't, but they might start not working as well in the future if you skip this
63 The generated file `resources/celerity/map.php` causes merge conflicts
64 quite often. They can be resolved by running the Celerity mapper. You can
65 automate this process by running:
67 phabricator/ $ ./scripts/celerity/install_merge.sh
69 This will install Git merge driver which will run when a conflict in this file
74 To include a CSS or JS file in a page, use
75 @{function:require_celerity_resource}:
77 require_celerity_resource('duck-style-css');
78 require_celerity_resource('duck');
80 If your map is up to date, the resource should now be included correctly when
83 You should place this call as close to the code which actually uses the resource
84 as possible, i.e. **not** at the top of your Controller. The idea is that you
85 should @{function:require_celerity_resource} a resource only if you are actually
86 using it on a specific rendering of the page, not just because some views of the
87 page might require it.
93 - reading about Javascript-specific guidelines in @{article:Javascript Coding
95 - reading about CSS-specific guidelines and features in @{article:CSS Coding