How to write MIME header for application/x-javascript?

F

Fengshui

I remember every CGI output must start as this:

print "text/html\n\n";

I guess what it does is it tells the client the type of the document as text
or html

I need to write a perl to let the client know it is a
application/x-javascript file.

What I try to do is that within the HTML page, there will be request for
extenal .js files, but I want the SRC="xxxx.cgi" and let the Perl script to
out put the .js file.

Anyone done this before?
 
G

Gunnar Hjalmarsson

Fengshui said:
I remember every CGI output must start as this:

print "text/html\n\n";

Then you remember wrong. The most common line in CGI scripts for
printing a HTTP header looks like this:

print "Content-type: text/html\n\n";
I need to write a perl to let the client know it is a
application/x-javascript file.

"Write a perl"? Do you possibly mean that you want to use the Perl
programming language for writing a CGI script?

And what is "it"?? Do you possibly want your CGI script output a HTML
page which shall call some JavaScript within <script></script> tags?
If that is the case, you shall not print anything but the usual
text/html content-type header. Another thing is that you need to let
the markup include something like this:

What I try to do is that within the HTML page, there will be
request for extenal .js files, but I want the SRC="xxxx.cgi" and
let the Perl script to out put the .js file.

Anyone done this before?

Well, I have not. I may be wrong, but I have a feeling that it can't
be done.

Maybe you should explain the reason why you want do do that. But if
you want to continue the discussion, you'd better do it in a more
appropriate newsgroup, such as comp.infosystems.www.authoring.cgi.
This group is for discussing Perl.
 
W

William Herrera

I remember every CGI output must start as this:

print "text/html\n\n";

I guess what it does is it tells the client the type of the document as text
or html

I need to write a perl to let the client know it is a
application/x-javascript file.

If you want to use perl to output a javascript file, you need to do something
like this with the perl CGI:

....
use CGI;
my $query = new CGI;
print $query->header(
-type=>'application/x-javascript',
-attachment=>'java.js'
);

print ... you print the .js file here ....
....etc.


What I try to do is that within the HTML page, there will be request for
extenal .js files, but I want the SRC=" x.cgi" and let the Perl script to
out put the .js file.

Anyone done this before?

Yes, with zip files. Question, though: why not let the web server handle it?
The only reason I ever did this was to send a file I'd made on the fly. If your
..js files are already made up, let the web server do what it was made for, and
just put links to the .js stuff in your other pages.

HTH,
 
B

Bart Van der Donck

Anyone done this before?

Yes, with Excel files.
I don't think it's such a good idea to generate your javascript files
separately. My provider uses heavy buffering on them.

The previous poster typed the code that you need. Personally, I would
code the javascript inside your main document. But maybe your .js file
is used by a lot of documents.

To avoid caching, you might use someting like:
<script language="javascript"
src="http://www.domain.com/javascript.js?RANDOMHERE"></script>

You'll need a server process to generate the random value. But in case
of a server process, I wonder why you wouldn't let the main document
generate the dynamic js code. Maybe you could let javascript generate
a random value in main file, and use that value to call your external
javascript to make sure you're not caching. I don't know if browsers
will get away with that, because then you start using <script> inside
<script> tags.

Bart
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top