I tried all the steps like
rm -rf var/*
php bin/magento setup:static-content:deploy -f
php bin/magento indexer:reindex
php bin/magento cache:clean
and still not worked. (These steps are required but it's incomplete)
You must have to change .htaccess
file with a new one in pub/static
whether exists or not.
After changing it, I ran cache:clean
command again, and then it works well for me.
Most people might skip this step because .htaccess is already available in pub/static.
You can get .htaccess
new one in magento official github:
https://github.com/magento/magento2/blob/2.3/pub/static/.htaccess
(It's for Magento 2.3, and you can choose your appropriate version in branch)
P.S: If u got memory exhausted error while running the commands, try with
php -dmemory_limit=5G bin/magento ...