Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

are there any negative implications of sourcing a javascript file that does not actually exist?

If you do script src="/path/to/nonexistent/file.js" in an HTML file and call that in a browser, and there are no dependencies or resources anywhere else in the HTML file that expect the file or code therein to actually exist, is there anything inherently bad-practice about doing this?

Yes, it is an odd question. The rationale is the developer is dealing with a CMS that allows custom (self-contained) javascript files to be provided in certain circumstances. The problem is the CMS is not very flexible when it comes to creating conditional includes for javascript. Therefore it is easier to just make references to the self-contained js files regardless of whether they are actually at the specified path.

Since no errors are displayed to the user, should this practice be considered a viable option?

like image 605
dreftymac Avatar asked May 20 '10 02:05

dreftymac


People also ask

Why do developers maintain JavaScript code in separate files to the HTML?

But if most of the Javascript is static, keeping it in separate files at development time keeps things organized. Dynamically generated Javascript can be served as separate files instead of being part of the page itself. It will add an extra HTTP call.

Where should JavaScript source code be included in an HTML document?

Using the script tag to include an external JavaScript file This script tag should be included between the <head> tags in your HTML document.

Where can a developer find which line in a web page of JavaScript file is causing a syntax error?

But the only way to find what line the error is on is to start commenting out the section of code I just wrote and reload it into the browser to narrow down where my missing ');' is.


1 Answers

Well the major drawback is performance since the browser will try (hard) to download the file and your server will look for it. Finally the browser may download the 404 page instead - thus slowing down the page load.

like image 164
Jakub Hampl Avatar answered Oct 11 '22 10:10

Jakub Hampl