CSS and JS not loading after installation of Magento default template


If you face problems after installing the Magento template and CSS and JS got stuck, then you have come to the right place. Here we will learn on how to fix the problems related to CSS and JS files that are not loading from a correspnding folder.

You might have done everything possible, but website still dosent load and you are faced with 404 responses, moreover no style or javascript are loaded. The following article will help you in solving the issue. It will describe the similar situation which happened in the environment.

If something goes wrong like what has happened in the current situation, check the browser console, If you note that there are attempts to access the files that are not in the pub/static folder among the other errors that has happened then you will be able to find the solution to the problem soon.


Why this issue Occur

If you redeployed  it after deleting the pub/static directory you would have deleted the .htaccess file in pub/static directory in your best website hosting services. That causes the URL Rewrite issue.

 

Put the .htaccess with url rewrite option in the pub/static directory , will resolve the problem



Css not loading in magento




How to fix this issue.

Step 1 

  • Kindly Login to the cPanel

 Step 2 
Once you have logged in to the cPanel we need to go the directory

  •  /home/public_html/pub/static

 Step 3 

 Step 4

After removing all the files in the web space go to file

  • app/etc/di.xml

 Step 5

After following the 4th step you need change Symlink to Copy in the file content.

  • Replace ('Symlink' --> 'Copy')

 

  • Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink

        to

  • Magento\Framework\App\View\Asset\MaterializationStrategy\Copy

 Step 6

Once you have followed all the above steps proerly you can save the file.

  • Save it