Can I Delete JS Files?

If you are responsible for a website, you may find many different types of files stored on your server. JavaScript files have the ".js" extension. Whether or not you can delete JavaScript files depends on the site you are working with. When you do remove them, it's always best to keep a copy on your local machine just in case you've missed something on the site. Before deciding whether to remove JavaScript files, you need to check for references to them in a variety of places.

JavaScript functions enhance website style and interactivity.


The main area to check for references to any JavaScript files you're thinking about removing is in the HTML head sections in your website. In each HTML page on the site, look between the opening and closing head tags for references to the JavaScript files, which should appear using markup similar to this example:

Check the "src" attributes of links like these to see if your JavaScript file names appear. If they do, there is a chance the page needs them to deliver its function.


Sometimes JavaScript files are referenced inside the body section in HTML pages. The markup is the same as linked scripts in the head section, but may appear anywhere in a page. Check between the opening and closing body tags in each HTML file on your site for references to your scripts. If you find any references in the body sections, removing the JavaScript files may affect the functionality of these pages.

Server Side Scripts

Depending on the technologies in a site, JavaScript file references may appear inside server side scripts. If your site uses files in either ASP or PHP languages, you should check these for JavaScript references. Often, server side scripts output HTML markup to send to the user's browser. This means that the HTML Web pages are contained inside programming code, as in the following PHP example: <?php echo "

"; ?>

Any JavaScript file references appearing in server side scripts may also be necessary for your site to function correctly.

Other Sites

JavaScript files are sometimes used across domains. For example, the following script reference imports the functionality from a file stored at a location that is different from the Web page:

This means that, even if your JavaScript files are not being used within the site stored at the same location, they may be needed elsewhere. For example, this is a common practice when a blog or other Web service does not allow users to upload scripts. By storing a script at a location that is under your control, you can make use of it elsewhere. For this reason, removing a JavaScript file may have an effect on other sites.