2

I wish to add a version number to my css file but I don't see a way to do it with the html helper.

I see one example of adding a timestamp through the bootstrap.php but I want to be able to control the version number myself.

I am using cakephp 2.3

style.min.css?v=1

<?php
    echo $this->Html->css('style.min', array('v'=>'1'));
    echo $this->fetch('css');
?>

or

<?php
    echo $this->Html->css('style.min?v=1');
    echo $this->fetch('css');
?>
1

2 Answers 2

4

Just add the .css

echo $this->Html->css('style.min.css?v=1');

Although it's standard practice to omit the .css, it's acceptable to include it, and will allow you to add additional parameters to the end of the URL.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, should have thought of that.
3

In CakePHP 3x you can do this in config/app.php.

/**
 * Apply timestamps with the last modified time to static assets (js, css, images).
 * Will append a querystring parameter containing the time the file was modified.
 * This is useful for busting browser caches.
 *
 * Set to true to apply timestamps when debug is true. Set to 'force' to always
 * enable timestamping regardless of debug value.
 */
'Asset' => [
    // 'timestamp' => true,
],

1 Comment

And in CakePHP 2.x it's in app/config/core.php. Just uncomment the following: Configure::write('Asset.timestamp', true); and consider setting it to 'force'. stackoverflow.com/a/14493811/1973005

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.