I'm modifying the checkout process, every time I edit a html file or a javascript file, I must use the command magento setup:static-content:deploy
because the html or javascript is cached by magento. Doing deployment is very time wasting, how to make the magento not to cache the static content? I've tried to switch to developer mode, but the static content still be cached.
Thanks
6 Answers
Require JS will cache the changes to your javascript files (even in developer mode). To disable caching, add the below to MyNamespace/MyModule/view/frontend/requirejs-config.js
var config = {
urlArgs: "bust=" + (new Date()).getTime()
};
-
I tried your solution, but it is not working with the minify js functionality, all the .min.js requests are redirecting to .js file urls and giving 404 error. Can you please tell me what might be the reason for it and any solution for it. Commented Jul 30, 2018 at 15:47
Enable developer mode and remove static files. In developer mode files will be redeployed on request. Please ensure that you web server is configured properly and do not add cache headers to static content files to avoid caching in browser.
-
Thanks for your answer, but as I said, problem exists after enabling developer mode.– Ricky.CCommented Mar 10, 2016 at 8:01
-
Do you try enable it by uncomment
SetEnv MAGE_MODE developer
in .htaccess ?– KAndyCommented Mar 11, 2016 at 8:38 -
-
Can you show with http headers have some static file? Also try check "Disable cache" on Network tab of Crome Developer Tools– KAndyCommented Mar 12, 2016 at 11:29
In Magento 2 this is sorted for you, just not documented well. Go to Config > Advanced > Developer > Static Files Settings > Sign Static Files > Yes
Even in developer mode also we have to execute the pub static content deploy whenever making changes in "web" folder
php bin/magento setup:static-content:deploy
In case have maximum execution time error try this
php -dmemory_limit=6G bin/magento setup:static-content:deploy
In my opinion there is no other way to deploy for particular module.
If you have the files already deployed and you need to do bigger development, i find it quickest to actually work with the deployed files and do the changes there.
Once you are happy with the results you can copy the files back to you module.
In your module add the following line, please add the line to your view/frontend/requirejs-config.js
like this:
var config = {
map: {
'*': {
shoppingCart: 'Magento_Checkout/js/shopping-cart',
sidebar: 'Magento_Checkout/js/sidebar',
checkoutLoader: 'Magento_Checkout/js/checkout-loader',
checkoutData: 'Magento_Checkout/js/checkout-data',
proceedToCheckout: 'Magento_Checkout/js/proceed-to-checkout'
}
},
urlArgs: "bust=" + (new Date()).getTime() // Disable require js cache
};
So you don’t need to clear the cache every time of the browser when you create any new extension