Results 1 to 7 of 7

Thread: Javascript File Includes Within HTML, Bad?

  1. #1
    Join Date
    Oct 2005
    Location
    Seattle, WA
    Beans
    494
    Distro
    Ubuntu 12.04 Precise Pangolin

    Javascript File Includes Within HTML, Bad?

    Greetings!

    I am currently doing work on a website and I was wondering if it is bad for SEO to do a JS file include from within the <body> tags of an HTML file.

    For example:

    HTML Code:
    <body>
    <div id="mydiv">
        <p>My Content</p>
        <br />
    </div>
    <script type="text/javascript" src="myJs.js"></script>
    <div id="newdiv">
        <p>More content for search engine to see.</p>
        <br />
    </div>
    </body>
    Would the spider die where the include happens? I know it isn't perfect practice, but I just don't want the spider to miss anything important.

    Thanks in advanced!
    www.runtime-era.com - Blog About My Journey as a Developer

  2. #2
    Join Date
    Feb 2010
    Location
    London
    Beans
    41
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Javascript File Includes Within HTML, Bad?

    I don't think it is an issue for the spider

    However it might be an issue the visitors. When the web browser reaches the script bloc it will stop rendering the page until it has loaded and executed that javascript.

    Therefore a script element in the middle of the page might slow its opening.

    That is why it is usually recommanded to load the javascript files at the end of the html document

    jf

  3. #3
    Join Date
    Apr 2008
    Beans
    286

    Re: Javascript File Includes Within HTML, Bad?

    On my website none of the content that is dynamically gets indexed by spiders. I therefore think they completely ignore JS...

  4. #4
    Join Date
    Feb 2006
    Beans
    468

    Re: Javascript File Includes Within HTML, Bad?

    HELLo!

    That they do, roccivic.

    Also, JS files should be included in the header, so that the browser can do parallel loading on them. Functions that generate dynamic content, however, should be executed once the DOM node has been fully rendered. Which is at the very end of the HTML document. jQuery and other JS libraries contain methods that substitute "onload", and postpones the running of the functions until the DOM has been rendered fully.

    Happy codin'!

  5. #5

    Re: Javascript File Includes Within HTML, Bad?

    Putting JavaScript in a separate file is a very good idea, especially with static (non CMS) websites. It allows the browser to cache the code, reducing file size and vastly reduces code redundancy.

    Also remember that anything added with javascript should also be available without it for usability (screen-readers) and SEO.
    im dyslexic, please don't comment on my spelling
    blender 3d artist, visit my portfolio
    Quad-Ren, Open source, resolution independent 2D graphics engine
    Screen space is a precious resource, don't waste it

  6. #6
    Join Date
    Apr 2007
    Location
    (X,Y,Z) = (0,0,0)
    Beans
    3,715

    Re: Javascript File Includes Within HTML, Bad?

    Ugh... it's horrible practice... It goes against MVC programming, against modularization and may even be against proper abstraction practices...

  7. #7
    Join Date
    Apr 2008
    Beans
    507

    Re: Javascript File Includes Within HTML, Bad?

    The optimum approach is to concatenate and compress all of your JS files into one. Then deliver this to the client. Have a look at YUI compressor (or similar) and GZIP compression.
    Go you good thing!

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
  •