Replacement for document.write

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amkohl
    New Member
    • Jul 2010
    • 10

    Replacement for document.write

    Hi,

    We are using the following code to generate the JS tag dynamically using PHP

    Code:
     echo 'document.write("<script type=\"text/javascript\" src=\"'.$jsPath.$value.'\"></script>");';
    However, we DO NOT want to use document.write since it allows the script to be deferred thereby increasing page load speed. Secondly we’re seen issues with the ‘lazy-loading’ of our scripts when the code is being included using document.write

    Can someone please let me know the replacement of document.write in PHP.

    Appreciate relevant reponses.
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    I may have misinterpreted this but using echo by itself should do the trick.
    Code:
     echo '<script type="text/javascript" src="' . $jsPath . $value . '"></script>';

    Comment

    • amkohl
      New Member
      • Jul 2010
      • 10

      #3
      OOps... that did not work. without using document.write did not generate the dynamic JS.

      Thanks!

      Comment

      • JKing
        Recognized Expert Top Contributor
        • Jun 2007
        • 1206

        #4
        Could you provide a larger code snippet to give this some context?

        Comment

        Working...