[Javascript] Javascript include problem?

Mike Dougherty mdougherty at pbp.com
Sat Oct 2 10:37:04 CDT 2010


On Fri, Oct 1, 2010 at 10:14 PM, John List <johnlist at gulfbridge.net> wrote:

>
> Jason, it looks like your "javascript page" is a complete html page, not
> just javascript. You are including that in another html page, so you wind up
> with multiple <html>, <head>, and <body> tags.
>
> Put your javascript only (no html) in its own .js file, and reference that
> file in a <script src= > tag in the head of the main page. (Or, if you
> prefer, use php to include it between  <script></script> tags in the head of
> the page.)
>
>
fwiw the external script ( <script src=...> ) is a much better solution
because browsers will retrieve and cache the script so it will not need to
be retrieved again on following page requests.  This lowers the overall
weight (and wait!) of a page download.

Using php to write script into a page (inside <script></script>) guarantees
that the extra X bytes will be downloaded with the markup on every page
request.

btw, by the time I was looking it appeared the problem was resolved.


More information about the Javascript mailing list