I have been Googleing for a possible answer to my question have have
gone no where with it. Anyway I am trying to figure out if it is
possible to place a link to an external JavaScript file in the header
section of a CGI script written in Perl. I currently have the
JavaScript directly in my page, but due to the codes length I’m sure it
has negative impact on the pages load time. Anyone here know if this is
possible?
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Unless I’m missing something you’re not going to be able to do anything
here. JavaScript in CGI land is typically client-only (meaning on the
user’s browser side) while Perl is almost exclusively (again, in CGI land)
server-side. Unless you have a JavaScript interpreter that you are
calling from Perl (like Rhino) to do your bidding it will be futile to try
to do this at all. Knowing what your JS does may help a bit more.
Good luck.
Adam Jimerson wrote:
> I have been Googleing for a possible answer to my question have have
> gone no where with it. Anyway I am trying to figure out if it is
> possible to place a link to an external JavaScript file in the header
> section of a CGI script written in Perl. I currently have the
> JavaScript directly in my page, but due to the codes length I’m sure it
> has negative impact on the pages load time. Anyone here know if this is
> possible?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iQIcBAEBAgAGBQJKGLQoAAoJEF+XTK08PnB5uj8P/0XI7TqTm9gXZF74RIsDB8y4
Fo+oflLJNlvkElss5ah3ckesHLHclpbMvbPP9DSzHHIlc775YIk1UZqVEylbFVvl
bcK12fLJGpepw9NNMxOHPKKcbxa3qfaEwrqHAiwHsDXpSSItT5TCHf7C2iAZVVzz
dOIFpSbqSZriHWh6gwyNtYgmYlUPYHudcqn47v1enjJbSE6mJy+TDlhVMuDsTmhI
gwG6Y4z63ud0hW3IOfPtynodEdNqKcGwK9XOmuA453wWKdOV1i3p8y/iCWh9TNPf
APOEj/wnhLW/A+zuZbdtP9xtVCj4mJoquINlUOFOxXzvbdTx0grudtfHHJI+ay2X
S2Zy1nbYREh7z+bd13doBbOSRcv3nF+2I9rH3ZdwxvA1ySrPYHCWj5N4YH1KdiC3
xbojgD7ETqT1pqWKgE3JK1PSOsQQfWHlVfEU8Lj3/MRvk1ETJQekg3OoougABXeR
QhLzX5VFIevfB/jeEmnBx32ARuKgvCBZf797kBNRBgHeaDW8hUUFQeGANPD59sq7
5F1yMZNqVTROmpqTjJlxSYt4P0ltdBQOkMkgacL/Qwmrwz0oTkwPTKYc/fPYgxfz
yGHlNJXKgpJ84PhEXMZs/cPEdAGPrZaOq2/wxO0Oub0g4p0qMWC7KMqRrYGYYZkm
71pCuVSlakhbP1QAKRSQ
=hFVk
-----END PGP SIGNATURE-----
The JavaScript is just a simple Image viewer, you can see the page and the JavaScript here -> Photo Viewer v0.4 its all working I just want to move the JavaScript out of my page and into an external file if possible, but the script doesn’t like to be anywhere outside of the header tags.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Use one of these instead:
http://javascript.crockford.com/script.html
Have your file separate but still include it from the HTML. This will let
your browser do caching of the file so it is not loaded over and over
which saves you (and visitors) bandwidth and makes updates to your JS
library publicly much simpler (update one file and you’re done).
Good luck.
vendion wrote:
> The JavaScript is just a simple Image viewer, you can see the page and
> the JavaScript here → ‘Photo Viewer v0.4’
> (http://www.vendion.net/cgi-bin/photoviewer.cgi) its all working I just
> want to move the JavaScript out of my page and into an external file if
> possible, but the script doesn’t like to be anywhere outside of the
> header tags.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iQIcBAEBAgAGBQJKGMLEAAoJEF+XTK08PnB553wP/30BjY2ure5c03d29hcBWJlQ
t28XFqeMwRCyAKc5msP1bCziV6/x4O3m9vnub6DbpATqvaFgabv+0/tPK+Pisbm4
Xkd2RGr7qOIWfvYbg6fckAQ9ROyEswx/Sb0DegOBOxETaitPxIbIjEKL1BHUPtDO
UYzou2yrsfwzbuvx0ZmZQipUh9Op+/Cpcq98wQwM8/z7266iLalu41O2n//yEKsT
DR5kqQv7YpImTv+cHje6Pw1whirQMGzTwj2xBI2Lo+7hHOqPY/XEsK1twtVmuqaQ
4E6LEByxfcQRzj90BYfsgNkY1EL0BSKyKbPuwet6yG9ti0gKQTlF6mmbeRIr3WwA
rWFQ8oLkWmYif8wS6WK4hRfKMiZxVhe4YMWgv6SjkbYjRE4EZWPGZY7fH8IZjhbw
/R5pMrH7Bi8JENROD0kmajmc+kCVGwseel+oijZZy34KzgYfW1IJIuxygywMAA1c
QZiDq7UJioisO4CP1XLHLO8ntmKKj/qPtf5QgCvH5hjO3hV0+hmZzsW2FftIxj2O
RWZvx+uwKCQ8fqWUWKd5vz+u2WwnZFyy3JFmGapMiGlxtPlXbeVKWBMO16VGq3Mk
Qut7Q/IX+naEurXfeBTSFSlFU2SrXm6PzHC9q/0CvMo5HSod8Ey8l1TQQShrRZ7f
Jyn/rpJiwnBidu8YOnvO
=cJG/
-----END PGP SIGNATURE-----
This is a template system issue. The Javascript <script> elements actually should go inside the <head> element, not the HTTP headers. If your templating system doesn’t allow you to put content into the <head> element, only in the <body> element, then it’s a deficiency of the system.
However it will work equally well if you put <script> tags in the <body> as long as Javascript objects are declared before use, just less clean. As AB suggested, put the code in an external .js file and use an external src in the <script> tag, instead of inserting the Javascript inline. However, browsers can get too aggressive in caching Javascript files, so good practice is to do this:
<script type='text/javascript' src='myjsprogram.js?buildid=20090524'></script>
where you put some kind of unique query parameter that changes whenever you change the JS file, to defeat the caching. Don’t forget the </script>, you will have missing content on your output if you do because browers are strict now.
That is what I am wanting to do, put the JavaScript code in an external file and just link to it on the page but I was trying to have the <script> link in the <head>. If my original post isn’t clear than I am sorry for the confusion, I will try putting the script link in the body and see if that will work.
Thanks for the help the <script> tags are working correctly from the body