Monday, May 18, 2009

Difference between Javascript in head and body section

Hi folks, I had very little knowledge in Javascript. So far, I have been stealing the scripts from some Javascript sites & blogs and ofcourse, google helped me a lot ;). Felt little asahmed to search for simple and basic Javascripts. So, started reading JS from scratch. Better late than never :)

Alright, this is a most basic concept that I read. This post might looks silly and funny for JS gurus. But, it is valuable piece of information for a newbie like me. 

JS is a sequence of statements to be executed by the browser. It can be embedded both in <head> and <body> sections of the HTML document. Sometime, this puts us in dilemma and can be solved by knowing the difference between embedding them in the above sections. 

JS in <head> Section :
      Scripts in this section will be executed when called, or when an event is triggered. This will ensure that the script is loaded before anyone uses it.

Example:

<html>
   <head>
      <script type="text/javascript">
         function message()
           {
               alert(This message is defined in head section and called with onload event");
           }
      </script
>
   </head>

   <body onload="message()">
   </body>
</html>


JS in <body> Section :
     Scripts in this section will be executed while the page loads. 

Example:

<html>
   <head>  </head>
   <body>
      <script type="text/javascript">
         document.write("This message is displayed on page load");
      </script
>
   </body>
</html
>
   
The above written JS is page specific. If you want to use the same script in multiple pages, save it as a Javascript file(.js) and include in the <head> section using <script> tag.


gud luck :)

Wednesday, May 6, 2009

Connecting to external libraries using svn:externals

Subversion is a version control tool used by many software developers to manage changes within their source code as a version tree.

More often we tend to use external libraries in our project. While the external library is already versioned somewhere, storing them locally in our project's library is a mere waste of memory and we have to manually update our local copy everytime the external library gets updated.

To overcome this, SVN came up with a property called svn:externals. Let's consider a Zend Framework project where we need Zend library. I am going to connect to the lastest version of ZF, which is 1.8.0. 

In our application, the Zend library resides in "library/Zend" folder. The svn externals property is set on the parent folder (library) and will contain the value Directory RepositoryURL.

To set a property using TortoiseSVN, right click on the "library" folder, and select "TortiseSVN->Properties". From the properties dialog, click "Add" and select "svn:externals" from the Property value drop-down. In the value field, add  Zend http://framework.zend.com/svn/framework/standard/tags/release/1.8.0/library/Zend

Save and close the dialogue box. Now, do svn update on the "library" folder. This will create a folder called "Zend" inside "library" and will checkout the external repo.

You can connect to many external repositories from the same directory by adding each of them in newline.

Ciao :)