-
-
Notifications
You must be signed in to change notification settings - Fork 814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CRM-20254: add cache buster string for custom CSS #9980
Changes from 1 commit
6f12c6e
595caa4
03449a5
33603e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -500,7 +500,7 @@ public function getUrl($ext, $file = NULL, $addCacheCode = FALSE) { | |
$file = ''; | ||
} | ||
if ($addCacheCode) { | ||
$file .= '?r=' . $this->getCacheCode(); | ||
$file = $this->addCacheCode($file); | ||
} | ||
// TODO consider caching results | ||
$base = $this->paths->hasVariable($ext) | ||
|
@@ -643,7 +643,8 @@ public function addCoreStyles($region = 'html-header') { | |
// Load custom or core css | ||
$config = CRM_Core_Config::singleton(); | ||
if (!empty($config->customCSSURL)) { | ||
$this->addStyleUrl($config->customCSSURL, 99, $region); | ||
$customCSSURL = $this->addCacheCode($config->customCSSURL); | ||
$this->addStyleUrl($customCSSURL, 99, $region); | ||
} | ||
if (!Civi::settings()->get('disable_core_css')) { | ||
$this->addStyleFile('civicrm', 'css/civicrm.css', -99, $region); | ||
|
@@ -881,4 +882,27 @@ private function resolveFileName(&$fileName, $extName) { | |
} | ||
} | ||
|
||
/** | ||
* @param string $url | ||
* @return string | ||
*/ | ||
public function addCacheCode($url) { | ||
parse_str(parse_url($url, PHP_URL_QUERY), $queryParts); | ||
$existing = isset($queryParts['r']) ? $queryParts['r'] : NULL; | ||
$latest = $this->cacheCode; | ||
|
||
if ($existing) { | ||
if ($existing === $latest) { | ||
return $url; // no need to update | ||
} | ||
else { | ||
return str_replace('r=' . $existing, 'r=' . $latest, $url); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, so this leads to my main confusion in the PR: I don't understand the scenario where (a) the URL already has There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @totten It's my unfamiliarity with the system that led me to putting that there to cover all cases. I thought maybe it might be possible that the cache buster string could change. If you can be sure it'll never happen I can rewrite it without it to just cover
Which should simplify things a lot There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that rewrite/simplification sounds good. The cache busting string does, of course, change from time-to-time, but I look at it this way:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @totten it's certainly a lot simpler with that change! I did a quick comparison on the performance of |
||
} | ||
} | ||
|
||
$operator = empty($queryParts) ? '?' : '&'; | ||
|
||
return $url . $operator . 'r=' . $latest; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was previous discussion on the best approach here from @totten which you can see here. It might look suspicious but I'm not trying to hide his comments ! I just messed up by opening the PR to the wrong branch.