2
votes

My drupal site isn't loading JS files nor CSS files located

sites/default/files/js 

OR

sites/default/files/css

even though they are there I can see them on FTP, their permissions are 664 and I can't change them they keep going back to 664. other files in sites/default/ are being loaded but not those.

Locally the site is working fine so I know it's a server issue! any suggestions?

5
Try a change a file permission 664 to 644 - Mehul Jethloja
@Mehul, I just tried, it got back to 664, I am unable to change it for some reason! - Amin
Have you clear the cache ? - Rupesh
what is permission of css and js folders? - Farnabaz
Have a look at this topic : drupal.stackexchange.com/questions/20364/… Hope it will help! - Djouuuuh

5 Answers

2
votes

First of all, it is not advisable to keep your JS & CSS files in sites/default folder. They should be kept in the sites/all/theme or sites/all/modules directory.

And, even then it is not necessary that they will be loaded on your website. You must specify it if you want to load these file on your site. This is how it is done:

For Theme:

add scripts[] = mytheme.js in the theme.info file to add js

add stylesheets[all][] = mytheme.css in the theme.info file to add css

For Module:

use drupal_add_js('path_to_file') to add js file

use drupal_add_css('path_to_file') to add css file

Considering that for some reason you have put the files in sites/default folder, you will need to provide the read permissions to the files. Its advisable to set them to 755.

1
votes

Have you checked your theme to make sure the css and js files are there? The info file?

1
votes

Make sure folders (sites/default/files/js and sites/default/files/css) permission is 755 or 744
it's important to User have executable permission to this folders

1
votes

The first question is, how do you include those css & Js to your site? using a module or from a theme? In all cases, you should put them either in the module directory or in the theme directory. If you put them in the theme directory, you should add those files to your .info file of the theme. This is the best way to include CSS/JS files to a theme.

0
votes

For clarity's sake

  • 404 means the server could not locate the resource (file in this case).
  • If you file permissions are 664, and it's parent folders are also 664, then anyone can read the file so this seems like a non issue.

@kellyjohnson is asking if the files exist, because of what the 404 error means conceptually. He seems to understand that you are observing the 404 in your browser console. That is agreed upon. But the natural question then is do the files physically exists where you expect them to be. If you can verify that files exist then there are only a couple options left to explore.

Cases

  1. In the case of public assets (assets under the application's document root), it's likely the server's document root is not what you believe it to be; in other words the absolute path to the files for which the server is attempting to server is not the same path to the physical location of your files.

    a) Debug this issue by determining your configured document root, which will likely be the base path of the main "index.php" application entry point. From there trace your relative path to your assets. If you still believe all is correct then the remaining option would be that the web server is rewriting your requests for assets, and that is where your attention should focus.

  2. In the case of non public assets (assets outside of the document root) it's likely your application routing is not routing to the directory you are assuming it should route to.

    b) this case is arguably the easier to debug, because you will enter the application which at any point you can echo debugging code, and trace the execution to the asset provider.

Good Luck.