Upon migrating to a new server not all of the CSS and JavaScript was loading. After some initial troubleshooting where I was seeing types errors in the console, and eliminating a missing REL attribute on the CSS or incorrect types listed for the CSS and JS files, I learned that the types errors could actually be, and then confirmed they were in this case, that the files were “missing”.
To mitigate this I took the following steps:
Updating the base, public and static secure/unsecure URLs in the database/.
Ensuring the URL’s ended in “/”
Toggling off and on the CSS and JavaScript merge
Deleting the contents of the pub/static/frontend/, pub/static/adminhtml/, var/view_preprocessed/, var/generated/ and var/cache/ folders.
Ran the following commands:
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento setup:static-content:deploy -f
bin/magento cache:clean
bin/magento cache:flush
Ensuring the pub/static/.htaccess file is present
Ensuring the re-deployed folders and files had the correct ownership
Ensuring the folders, especially those redeployed had the correct permissions using:
find . -type d -exec chmod 755 '{}' \;
find . -type f -exec chmod 644 '{}' \;
find var -type d -exec chmod 777 {} \;
find pub/static -type d -exec chmod 777 '{}' \;
find pub/media -type d -exec chmod 777 '{}' \;
chmod 777 app/etc
chmod 644 app/etc/*.xml
Refreshing my browser’s cache
I was following steps 3 through 7 plus 9 several times and it was showing the same behavior.
Digging a little deeper I was able to determine that, each time after following those steps, the browser was consistently pulling the deployment version that was one version behind the version listed as current in the deployed_version.txt file.
After realizing the redeployment was adding in different file ownership and permissions I added step 8.
Despite the deployed version the browser is trying to pull from now matching the current version listed in the deployed_version.txt file, and confirming that the files exists in the directories that they are pulling from, I’m still getting the type error which is causing the loading of the css and js files to fail.
Any insight into what combination of commands, files changes, or database changes might fix this behavior would be greatly appreciated.
Magento Version:
Server Configuration:
Ubuntu 18.04
Nginx 1.21.6
MariaDB 10.7.7
PHP 7.3.33