1

Is there a way to include the prototype.js code directly in the html file? I do not want to have something like this:

<script type="text/javascript" src="/path/to/prototype.js"></script>

I want something like this:

<script type="text/javascript" >
// the code of prototype.js to be here 
</script>

The context for what I want this is more complex. I just want to know now if this is possible or not. P.S.I'm not very familiar with Prototype.

Thank you.

3
  • 3
    Yes (you could have just tried before), although including it as an external file is better. You don't have to be familiar with Prototype.js in order to do or know that. Commented May 3, 2011 at 6:51
  • 2
    Including it externally means you can cache control it to be downloaded once per visit to your site (or possibly already be cached if pointing to Google's version on its CDN). Commented May 3, 2011 at 6:55
  • please see the my comment from David answer Commented May 3, 2011 at 8:22

2 Answers 2

4

Yes it will work if you copy paste the entire content inside the script tags.

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

4 Comments

I've tried this. I've copied inside script tags the code from here First I've get this error in Firefox Error Console: "missing ; before statement". Looking at column error number I saw that this was at line timeout = timeout * 1000 - was missing a ; . I put that ; and now I get another error: Error: missing } after function body and now the column error number is the end of the file ... I'm not sure which is the problem...
where are you testing it? works fine for me on a local server
I'm actually reading line by line a HTML file from a Java class and using a PrintWriter to print it. I've managed somehow to include it and to not return those errors anymore, but now, when I'm pressing a button which calls a method in which I'm using the function $(element) from Prototype I get another error: Error: $ is not defined Source code I'm using: $('submitForm') where submitForm is the id of a form.
I've put all the functions in the same script tag and when pressing a button on the form - calling at onclik a function I receive an error saying that that function is not defined.
1

We do something similar with jQuery and our other JS and CSS files for our web app. They are all compressed and included inline when we run our deployment script.

It makes the page relatively heavy (300kb) but the main advantage is you get everything in a single http request. This makes the app look very fast.
The page is then cached, making next visits even more responsive.

Comments

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.