Any way to check that a .js file is being really included?

Hi,

im starting with Javascript…

When you include in the <head> a line like this:

<script type=“text/javascript” src=“/js/file.js”></script>

You are trying to include the file.js, but is there any way to check that the file is being really included?

I mean, if i write any other name for example file1234.js, i dont get any error message…:confused:

Regards

Javi

Write some JavaScript which checks whether something defined in the external file is, in fact, defined.

If your using firefox - download firebug. You can track all page assets and server responses. Its invalueable asset for general web developement - no just for Javascript debugging.

If you using a WebKit browser then you can use the developer tools to check that your files were loaded correctly

If you have a server to upload your test pages to and are using Firefox, you can use FireBug (a Firefox add-on) to check what files are being downloaded when your page loads.

The FireBug window will need to be open when the page loads in order for it to gather data, but you can just refresh the page if you forget to open it before going to the site. I’ve attached a screenshot with notes so you can see what it would look like.

The NET panel will show you all files downloaded with your page (images, .css, .js, etc), and you can narrow it down by file type in the second tab level. If a file is being downloaded, it will show up in the NET panel, although it may not show everything if you are viewing a local file on your computer - that’s why I stated you would need a server for this. [NOTE: This is from user experience, not an in-depth/technical knowledge of the add-on.]

As for whether or not the javascript actually works… well, that’s a separate matter.

For Opera - Tools, Advanced, Developer Tools, Script tab - will open the JavaScript debugging facility

For IE8 - Tools, Developer Tools, Script tab - will open the JavaScript debugging facility

For earler versions of IE install the Developer Toolbar plugin first.

For Safari or Chrome - Current page controls, Developer, JavaScript Console - (current page controls is the page symbol at the top right of the browser) will open the JavaScript debugging facility

For Firefox you need to first install the Venkman extension and then access it via - Tools, JavaScript Debugger

In all cases you then have the ability to track exactly what JavaScript is/isn’t running and what values are assigned to what fields when. All of the debuggers work basically the same way, only the way you access them is slightly different.

When I want to check if a JavaScript is functioning at the correct interval, I add an alert button to the function to signify the event being triggered. Granted this is a temporary thing but it’s a lovely simple method of testing scripts without impacting the interface - and you can have it return a string of data into the box so you can check that values are as they should appear too. Though using a debugger like felgall mentioned is also a good route. :slight_smile:

Thanks for your posts.

I tend to do that too. Really should start making more use of the debuggers that all browsers except for Firefox have built in though - not much point in the debuggers being there if you don’t use them.