Created
March 7, 2014 20:26
-
-
Save nathanbrauer/9419319 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: filesystem/File.php | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- framework/filesystem/File.php (revision 8518) | |
+++ framework/filesystem/File.php (revision 8519) | |
@@ -640,13 +640,29 @@ | |
} | |
/** | |
+ * Returns a string that can be added to the end of a URL | |
+ * to prevent browser cache from loading old images and files | |
+ * | |
+ * @return string | |
+ */ | |
+ protected function getCacheBuster() { | |
+ $LastEdited = $this->LastEdited; | |
+ if (!$LastEdited) { | |
+ $Original = File::find($this->getFilename()); | |
+ if (!$Original || !$Original->LastEdited) return ''; | |
+ $LastEdited = $Original->LastEdited; | |
+ } | |
+ return '?'.preg_replace('/[^0-9]+/i','',$LastEdited); | |
+ } | |
+ | |
+ /** | |
* Gets the absolute URL accessible through the web. | |
* | |
* @uses Director::absoluteBaseURL() | |
* @return string | |
*/ | |
public function getAbsoluteURL() { | |
- return Director::absoluteBaseURL() . $this->getFilename(); | |
+ return Director::absoluteBaseURL() . $this->getFilename() . $this->getCacheBuster(); | |
} | |
/** | |
@@ -656,7 +672,7 @@ | |
* @return string | |
*/ | |
public function getURL() { | |
- return Director::baseURL() . $this->getFilename(); | |
+ return Director::baseURL() . $this->getFilename() . $this->getCacheBuster(); | |
} | |
/** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment