Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add timestamps to development-mode static resource URIs

Summary:
When a developer changes CSS, it is normally sufficient to reload the page to get changes to show up, because browsers revalidate resources on reload.

However, if you reload the page and then an Ajax request adds new CSS to the page, this CSS does not trigger revalidation. The developer must currently clear their cache or re-run `scripts/celerity_mapper.php webroot`, to get this request to skip cache. We rarely use CSS over Ajax right now, so this hasn't cropped up much, but Conpherence does use this and clearing the resource is a big pain.

This seems to work fine normally, but I'm worried it might break some of the extra-celerity-resources stuff Facebook is doing.

Test Plan: In development mode, changed `conpherence/message-pane.css` and saw changes reflected on reload. Verified normal page loads do not cause additional HTTP requests. This change has no effect in production mode.

Reviewers: edward, vrana, btrahan

Reviewed By: vrana

CC: aran

Maniphest Tasks: T2428

Differential Revision: https://secure.phabricator.com/D4902
  • Loading branch information...
commit 1e74c05ac6ff89ae9e8227f7a02573bfb3fbe34e 1 parent ca0d6ac
@epriestley epriestley authored
View
1  src/aphront/configuration/AphrontDefaultApplicationConfiguration.php
@@ -122,6 +122,7 @@ public function getURIMap() {
protected function getResourceURIMapRules() {
return array(
'/res/' => array(
+ '(?:(?P<mtime>[0-9]+)T/)?'.
'(?P<package>pkg/)?'.
'(?P<hash>[a-f0-9]{8})/'.
'(?P<path>.+\.(?:css|js|jpg|png|swf|gif))'
View
32 src/infrastructure/celerity/CelerityStaticResourceResponse.php
@@ -103,7 +103,7 @@ private function renderPackagedResources(array $resources) {
}
private function renderResource(array $resource) {
- $uri = PhabricatorEnv::getCDNURI($resource['uri']);
+ $uri = $this->getURI($resource);
switch ($resource['type']) {
case 'css':
return phutil_tag(
@@ -206,7 +206,7 @@ public function buildAjaxResponse($payload, $error = null) {
$this->resolveResources();
$resources = array();
foreach ($this->packaged as $resource) {
- $resources[] = PhabricatorEnv::getCDNURI($resource['uri']);
+ $resources[] = $this->getURI($resource);
}
if ($resources) {
$response['javelin_resources'] = $resources;
@@ -215,4 +215,32 @@ public function buildAjaxResponse($payload, $error = null) {
return $response;
}
+ private function getURI($resource) {
+ $uri = $resource['uri'];
+
+ // In developer mode, we dump file modification times into the URI. When a
+ // page is reloaded in the browser, any resources brought in by Ajax calls
+ // do not trigger revalidation, so without this it's very difficult to get
+ // changes to Ajaxed-in CSS to work (you must clear your cache or rerun
+ // the map script). In production, we can assume the map script gets run
+ // after changes, and safely skip this.
+ if (PhabricatorEnv::getEnvConfig('phabricator.developer-mode')) {
+ $root = dirname(phutil_get_library_root('phabricator')).'/webroot/';
+ if (isset($resource['disk'])) {
+ $mtime = (int)filemtime($root.$resource['disk']);
+ } else {
+ $mtime = 0;
+ foreach ($resource['symbols'] as $symbol) {
+ $map = CelerityResourceMap::getInstance();
+ $symbol_info = $map->lookupSymbolInformation($symbol);
+ $mtime = max($mtime, (int)filemtime($root.$symbol_info['disk']));
+ }
+ }
+
+ $uri = preg_replace('@^/res/@', '/res/'.$mtime.'T/', $uri);
+ }
+
+ return PhabricatorEnv::getCDNURI($uri);
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.