@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 62 lines 3.0 kB view raw
1@title Celerity Technical Documentation 2@group developer 3 4Technical overview of the Celerity system. 5 6= Overview = 7 8Celerity is a static resource (CSS and JS) management system, which handles: 9 10 - Keeping track of which resources a page needs. 11 - Generating URIs for the browser to access resources. 12 - Managing dependencies between resources. 13 - Packaging resources into fewer HTTP requests for performance. 14 - Preprocessing resources (e.g., stripping comments and whitespace). 15 - Delivering resources and managing resource cache lifetimes. 16 - Interfacing with the client to manage resources. 17 18Celerity is an outgrowth of the //Haste// system at Facebook. You can find more 19information about Celerity here: 20 21 - @{article:Things You Should Do Soon: Static Resources} describes the history 22 and context of the system and the problems it solves. 23 - @{article:Adding New CSS and JS} provides a developer guide to using 24 Celerity. 25 26= Class Relationships = 27 28Celerity's primary API is @{function:require_celerity_resource}, which marks a 29resource for inclusion when a response is rendered (e.g., when the HTML page is 30generated, or when the response to an Ajax request is built). For instance, if 31you use a CSS class like "widget-view", you must ensure the appropriate CSS is 32included by calling `require_celerity_resource('widget-view-css')` (or 33similar), at your use site. 34 35This function uses @{class:CelerityAPI} to access the active 36@{class:CelerityStaticResourceResponse} and tells it that it needs to include 37the resource later, when the response actually gets built. (This layer of 38indirection provides future-proofing against certain complex situations Facebook 39eventually encountered). 40 41When the time comes to render the response, the page renderer uses 42@{class:CelerityAPI} to access the active 43@{class:CelerityStaticResourceResponse} and requests that it render out 44appropriate references to CSS and JS resources. It uses 45@{class:CelerityResourceMap} to determine the dependencies for the requested 46resources (so you only have to explicitly include what you're actually using, 47and not all of its dependencies) and any packaging rules (so it may be able to 48generate fewer resource requests, improving performance). It then generates 49`<script />` and `<link />` references to these resources. 50 51These references point at `/res/` URIs, which are handled by 52@{class:CelerityResourceController}. It responds to these requests and delivers 53the relevant resources and packages, managing cache lifetimes and handling any 54necessary preprocessing. It uses @{class:CelerityResourceMap} to locate resources 55and read packaging rules. 56 57The dependency and packaging maps are generated by `bin/celerity map`, 58which updates `resources/celerity/map.php`. 59 60@{class:CelerityStaticResourceResponse} also manages some Javelin information, 61and @{function:celerity_generate_unique_node_id} uses this metadata to provide 62a better uniqueness guarantee when generating unique node IDs.