On one of my websites, sometimes some of my customs js not working, I have embedded them on a template file. I have checked the console of the browser it shows an error, also sometimes CSS or some portion like sign-in/sign out or logo will not display.

to fix it I have to run content deploy every time, I just need to know the root cause of it. What will be the best practices to fix this kind of issue, so that I don't have to run content deploy every time, as the website is already live, and it seems very disappointing if suddenly some function stop working.

Also, I have noticed that content deploy is not working with -f is that was also an issue, which brings these problems.


  • Which mode you are using ?
    – Pawan
    Commented Nov 28, 2018 at 11:54
  • currently its development mode.
    – Akash
    Commented Nov 28, 2018 at 12:18
  • have you added JS code to phtml file ? Please also share what code you have added ?
    – Pawan
    Commented Nov 28, 2018 at 12:39
  • yes i did it in on template file. It was a plain js script for validating form nothing else. script is working fine without throwing any error on console logs.
    – Akash
    Commented Nov 28, 2018 at 12:44

2 Answers 2


Please try the steps as described below.

I assume Magento is on Developer mode while you follow the below steps.

step 1) Please Go to Admin panel and navigate to STORES -> Configuration -> ADVANCED -> DEVELOPER .

Click on "JavaScript Settings" to expand it.

Step 2) Please set JavaScript Settings as follows:

  • Merge JavaScript Files : Yes
  • Enable JavaScript Bundling : No
  • Minify JavaScript Files : No

Step 3) Run Following CLI commands from your Magento 2 root directory to remove static files, generated files, cache files.

sudo rm -rf var/view_preprocessed/*
sudo rm -rf var/pub/static/*
sudo rm -rf var/cache/*
sudo rm -rf var/generated/*
sudo rm -rf var/page_cache/*
sudo rm -rf var/view_preprocessed/*
sudo rm -rf pub/static/frontend/*

step 4:) Again please run the below CLI commands to set Production mode

sudo php bin/magento deploy:mode:set production -s

sudo php bin/magento setup:di:compile

sudo php bin/magento setup:static-content:deploy

Step 5) Run the below commands to set permission to the pub, var, and generated folder

sudo chmod -Rv 777 pub var generated

You can run the static-deploy in verbose mode with -vvv and that might show more output assuming its hitting an error when your custom JS is not there.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.