Skip to content

Commit

Permalink
Disabling caching of JS files by default. Requiring webroot to be
Browse files Browse the repository at this point in the history
writable by default it not a good idea.
  • Loading branch information
markstory committed Mar 20, 2009
1 parent 0bd3cc9 commit f15b793
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cake/libs/view/helpers/js.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function call__($method, $params) {
* *
* - 'inline' - Set to true to have scripts output as a script block inline * - 'inline' - Set to true to have scripts output as a script block inline
* if 'cache' is also true, a script link tag will be generated. (default true) * if 'cache' is also true, a script link tag will be generated. (default true)
* - 'cache' - Set to true to have scripts cached to a file and linked in (default true) * - 'cache' - Set to true to have scripts cached to a file and linked in (default false)
* - 'clear' - Set to false to prevent script cache from being cleared (default true) * - 'clear' - Set to false to prevent script cache from being cleared (default true)
* - 'onDomReady' - wrap cached scripts in domready event (default true) * - 'onDomReady' - wrap cached scripts in domready event (default true)
* - 'safe' - if an inline block is generated should it be wrapped in <![CDATA[ ... ]]> (default true) * - 'safe' - if an inline block is generated should it be wrapped in <![CDATA[ ... ]]> (default true)
Expand All @@ -131,7 +131,7 @@ function call__($method, $params) {
* @return string completed javascript tag. * @return string completed javascript tag.
**/ **/
function writeScripts($options = array()) { function writeScripts($options = array()) {
$defaults = array('onDomReady' => true, 'inline' => true, 'cache' => true, 'clear' => true, 'safe' => true); $defaults = array('onDomReady' => true, 'inline' => true, 'cache' => false, 'clear' => true, 'safe' => true);
$options = array_merge($defaults, $options); $options = array_merge($defaults, $options);
$script = implode("\n", $this->getCache($options['clear'])); $script = implode("\n", $this->getCache($options['clear']));


Expand Down
4 changes: 3 additions & 1 deletion cake/tests/cases/libs/view/helpers/js.test.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function testWriteScriptsInFile() {
$this->Js->JsBaseEngine = new TestJsEngineHelper(); $this->Js->JsBaseEngine = new TestJsEngineHelper();
$this->Js->writeCache('one = 1;'); $this->Js->writeCache('one = 1;');
$this->Js->writeCache('two = 2;'); $this->Js->writeCache('two = 2;');
$result = $this->Js->writeScripts(array('onDomReady' => false)); $result = $this->Js->writeScripts(array('onDomReady' => false, 'cache' => true));
$expected = array( $expected = array(
'script' => array('type' => 'text/javascript', 'src' => 'preg:/(.)*\.js/'), 'script' => array('type' => 'text/javascript', 'src' => 'preg:/(.)*\.js/'),
); );
Expand All @@ -180,6 +180,8 @@ function testWriteScriptsInFile() {
$this->assertTrue(file_exists(WWW_ROOT . $filename[1])); $this->assertTrue(file_exists(WWW_ROOT . $filename[1]));
$contents = file_get_contents(WWW_ROOT . $filename[1]); $contents = file_get_contents(WWW_ROOT . $filename[1]);
$this->assertPattern('/one\s=\s1;\ntwo\s=\s2;/', $contents); $this->assertPattern('/one\s=\s1;\ntwo\s=\s2;/', $contents);

@unlink(WWW_ROOT . $filename[1]);
} }
} }


Expand Down

0 comments on commit f15b793

Please sign in to comment.