Apache JavaScript Directory Inaccessible

Shortly after setting up a fresh installation of Apache, I uploaded a website, only to find that none of the JavaScript was loading. It turns out that Apache helpfully provides you with a common JavaScript directory but if you’re not using it you may need to turn it off.

Why Isn’t My JavaScript Loading?

My website included a /javascript/ directory and I soon discovered that I was getting 404 Not Found responses when trying to load any of the scripts. I double-checked the spelling, that I had actually uploaded them, and that the directory and file permissions were correct. Nothing worked.

Apache’s javascript-common Configuration

Finally I discovered an Apache configuration called javascript-common that helpfully allows JavaScript to be shared between vhosts in a central location. But as a consequence if you have an actual directory named /javascript/ Apache will look instead at the shared location rather than your local directory.

Disabling the common JavaScript location requires just one shell command:

a2disconf javascript-common

And after that your local JavaScripts will work again.

Leave a Reply

Your email address will not be published. Required fields are marked *