CakePHP – How to Force refresh of modified JS & CSS file in cakephp?

QuestionsCategory: CakephpCakePHP – How to Force refresh of modified JS & CSS file in cakephp?
Roboto asked 3 months ago

I want to load the Updated CSS, JS files  when its modified. Not from the cache.

1 Answers
Best Answer
devchandan Staff answered 3 months ago

For the CakePHP the Versioning of URL option is already exists in core.php
Check in core.php

/**
* Apply timestamps with the last modified time to static assets (js, css, images).
* Will append a query string parameter containing the time the file was modified. This is
* useful for invalidating browser caches.
*
* Set to `true` to apply timestamps when debug > 0. Set to 'force' to always enable
* timestamping regardless of debug value.
*/
// Configure::write('Asset.timestamp', true);
Configure::write('Asset.timestamp', 'force');

 
In CakePHP 3.x (in config/app.php)

'Asset' => [
    'force'
]

In CakePHP 2.x (in app/Config/core.php)

 Configure::write('Asset.timestamp', 'force');

 
If you only want to apply the timestamps while debug mode is enabled set the above to true instead of force.