1

What is the best way to load a common Javascript chunk of code from a file on a simple website? I need to add a script that tracks users for the Piwiki Open Source Analytics. I have hardly worked with Javascript, and just wanted to know what should I do?

<!-- Piwik -->
blah blah blah
<!-- End Piwik Tag -->

Basically, I don't want to have to update the entire site if I make a change.

2 Answers 2

1

Include this wherever you would like that script to appear:

<script type="text/javascript" src="scripts/code.js"> </script>

Then, in scripts/code.js, include the relevant analytics code.

Sign up to request clarification or add additional context in comments.

1 Comment

Don't use XML self-closing tag syntax. The question is tagged html, and it isn't suitable for HTML-Compatible XHTML either.
0

Just put the javascript in a file and include that file in every page.

Normally, you put it at the end of the html, just before the end of the body, so it would look something like:

...
<script type="text/javascript" language="JavaScript" src="/my_scripts/piwiki.js"></script>
</body>

1 Comment

How do includes work in basic HTML? These are not even PHP pages I'm working on

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.