SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Hybrid View

  1. #1
    SitePoint Addict gthorley's Avatar
    Join Date
    Oct 2000
    Location
    Canada
    Posts
    392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I keep reading that it is recommended to place your javascript code in a seperate file and then load that file in order to keep your site content closer to top for search engine purposes.

    Could someone explain just what is done and does anyone really do this. In looking at source code I haven't yet seen this. Haven't spent hours lookinhg though.

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2001
    Location
    Toronto, Ontario, Canada, Earth
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    to include a javascript file, try this code:

    Code:
    <script language="JavaScript" src="script.js">
    </script>
    Jason Weinstein
    webmaster@MaximumEdge.com
    http://www.MaximumEdge.com/

  3. #3
    Irritability Defined
    Join Date
    Jul 2000
    Location
    80,000 feet below the surface
    Posts
    1,442
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are a couple of advantages in placing all your JavaScript in a single file :

    1. You can use it anywhere, and don't have to repeat the code ad nauseum.

    2. The script file (.js) will be cached the first time you use it.

    3. Cleaner HTML code.
    My 2 Cents (or is that 2.2 Cents including GST?)

  4. #4
    SitePoint Addict gthorley's Avatar
    Join Date
    Oct 2000
    Location
    Canada
    Posts
    392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok so in the place where I have the javascript I insert
    <script language="JavaScript" src="script.js">
    </script>

    Now how do I create script.js? Is this a text file, similar to a *.css file?

    Everything else stays the same and the above is loaded in the head area?

    Thanks for the help.

  5. #5
    SitePoint Zealot
    Join Date
    Apr 2001
    Location
    Toronto, Ontario, Canada, Earth
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by gthorley
    Now how do I create script.js?
    you create it by inserting whatever you would have had in <script> tag and saving it as a text file. for example, the text file could contain the following:

    Code:
    document.write('hello');
    Jason Weinstein
    webmaster@MaximumEdge.com
    http://www.MaximumEdge.com/

  6. #6
    SitePoint Addict gthorley's Avatar
    Join Date
    Oct 2000
    Location
    Canada
    Posts
    392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The script that I am moving is a rollover created by dreamweaver and is enclosed in the following tags
    <!--
    "javascript code is here"
    //-->

    Do I place these in the text file or just the script. Can I remove them from the original page?

    On a test I didn't include them in the text file and removed them from the main page. I seems to work but as I have had code work with errors before I thought I better check.

  7. #7
    pg for mild peril cow's Avatar
    Join Date
    Mar 2000
    Location
    nevada, usa
    Posts
    636
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the comment tags <!-- //--> are used to prevent browsers that can't utilize the code from reading it.

    when you put your script in an external file, you are already doing this step for the browser. so, no, you don't need to include those extra tags. even if you do, it doesn't matter...

  8. #8
    SitePoint Enthusiast Setac's Avatar
    Join Date
    Nov 2000
    Location
    San Marcos CA
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are doing this for better position in the search engines, its effect is minimal for most Dreamweaver code.

    You can get more effect by moving all your meta tags and placement comments ahead of the scripts.

    You can also place layers (div) anywhere on the page and then later move the code around inside the file without affecting appearance. This will allow you to move content that is important for placement rating to the beginning of the file.

    You can also move scripts around but you have to know what is needed when in the load sequence before attempting that.
    Dynamic HTML - Is that a Frisbee based language...

  9. #9
    SitePoint Enthusiast Setac's Avatar
    Join Date
    Nov 2000
    Location
    San Marcos CA
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, another problem with DW is that if you move DW's code out to a JS file, you will have problems editing the file in DW. DW will also insert another copy of the code in the file the next time you save it from DW.
    Dynamic HTML - Is that a Frisbee based language...

  10. #10
    SitePoint Addict gthorley's Avatar
    Join Date
    Oct 2000
    Location
    Canada
    Posts
    392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Setac
    Oh, another problem with DW is that if you move DW's code out to a JS file, you will have problems editing the file in DW. DW will also insert another copy of the code in the file the next time you save it from DW.
    I am unable to duplicate any problem. Are you talking about editing the menu.js file? Why would I edit this in DW and not a text editor?

  11. #11
    SitePoint Enthusiast Setac's Avatar
    Join Date
    Nov 2000
    Location
    San Marcos CA
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No... your right it does work. I remember having a problem with DW and moving their code around. But, I tried it and you are right it works fine. I learned something. Maybe it was my DW3... but I had played with it so much it was somewhat broken.

    It is true that you cannot edit scripts from include files with DW script edit button. But as you pointed out most people probably use another editor for javascript.

    Alan
    Dynamic HTML - Is that a Frisbee based language...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •