SharePoint script debugging

_SP2007

In SharePoint you have (or at least I have) the tendency to add JavaScript or JQuery scripts directly into a Content Editor Web Part on the page. This is indeed the easiest way, but this practice makes script debugging a cumbersome task.  A good way is to set “alerts()” in the in the script to make you show what’s happening. But even that can be painful when going through a loop.

How about we do it the same way we would do it on any other HTML website.

Create a Document Library (call it Scripts or whatever you like) and simply collect all your scripts for this site in this library.

Only copy the reference into the Content Editor Web Part on the page.

For example:

<script type=”text/javascript” src=”https://servername /sites/ site/Scripts/scriptname.js”></script>

This way you can simply make changes to the scriptname.js file on your computer and upload it to the Document Library. Refresh the page (F5) and the script will run.

The biggest advantage however is the debugging you can do that way. Simply hit F12 in Internet Explorer to start the Developer Tools. Click “Script” on the toolbar and select the scriptname you want to debug in the drop down list. Here you see only what is happening to your script and you can set breakpoints, conditions, watch variables and so on.

Is this Pages usefull? Usefull Useless 3 of 3 people say this Pages is usefull.