content-length as a META tag?

R

relaxedrob

Hi All!

I have some programming to do where I can make use of the
content-length header if it is available.

My question is can we (and should we) include a content-length META
tag in the HEAD element or can we only insert a content-length header
through some server language such as ASP/JSP/PHP/Perl etc?

Thanks for any advice!

Rob
:)
 
T

Toby A Inkster

My question is can we (and should we) include a content-length META
tag in the HEAD element or can we only insert a content-length header
through some server language such as ASP/JSP/PHP/Perl etc?

With dynamically generated pages (ASP/JSP/PHP/Perl/etc) you generally
don't know the Content-Length in advance.

With statically served files, most web servers (tested IIS and Apache)
seem to insert the Content-Length for you.

This leaves only gateway-type CGI files -- for example, some kind of
download.cgi script that checks various authorisation variables,
increments hit counters or whatever before sending the user a file.

This is pretty easy to do. For example, with Perl:

print 'Content-Length: ', (-s $file), "\n";'

Of course, setting a META tag is more difficult as the tag itself
will change the file size!
 
J

Joshua Beall

Hi All!

I have some programming to do where I can make use of the
content-length header if it is available.

My question is can we (and should we) include a content-length META
tag in the HEAD element or can we only insert a content-length header
through some server language such as ASP/JSP/PHP/Perl etc?

I do not understand what the purpose of setting the content-length via a
META tag would be. Why would you do this?

Anyway,. the point of setting the content length (I assume) is so that the
browser knows how long the document is going to be. Apache, at least, takes
care of this automatically for both images and html (both static and
dynamically rendered, e.g., PHP/ASP/JSP). See for yourself: telnet to port
80 of an apache server and do a get request. You will notice that right
before the first line of content is server, the length of the document, in
hex, is displayed.
 
J

Joshua Beall

Joshua Beall said:
I do not understand what the purpose of setting the content-length via a
META tag would be. Why would you do this?

Anyway,. the point of setting the content length (I assume) is so that the
browser knows how long the document is going to be. Apache, at least, takes
care of this automatically for both images and html (both static and
dynamically rendered, e.g., PHP/ASP/JSP).

I was wrong: for static HTML pages, it just sends the content-length header.
It is only for PHP pages that it prepends the output with the length.

Also, I imagine not many people are running ASP via Apache, and I have not
actually tested JSP. I spoke out of turn; sorry.
 
J

Joshua Beall

Toby A Inkster said:
With dynamically generated pages (ASP/JSP/PHP/Perl/etc) you generally
don't know the Content-Length in advance.

Hmm, perhaps, but it is not hard to if you want to:

ob_start();

{generate page}

$output = ob_get_contents();
ob_end_clean();
$length = strlen($output);

header("Content-length: $length");

Of course, if you wanted to add a meta tag, you would have to do some other
shenanigans, since it would change the content length. But I am still not
sure why you would want a meta tag with the content length.
 
M

Mark Parnell

Also, I imagine not many people are running ASP via Apache

We are. Causes lots of headaches. :-( I'm going to convert it to PHP
when I know it well enough.
 

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

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top