2

I've built a custom content management system on our intranet which allows us to update news articles and content across several sites that I operate. It appears to be working well.

However the other day I suddenly remembered that I'm not sending the HTTP content-length header when outputting articles on the websites. I send last-modified using the modification date of the article from the database.

Just wondering if I should also calculate the content-length of the whole page before it's sent to the client? Would it be best practice to send the content-length header or does it have any significant search engine benefits?

Cheers, B

Jared Farrish
  • 48,585
  • 17
  • 95
  • 104
batfastad
  • 1,943
  • 3
  • 27
  • 37

1 Answers1

0

You are required by the standard section 14.13 to send content-length... only exception is when you use "chunked transfer", but for that you have some other requirements...

Yahia
  • 69,653
  • 9
  • 115
  • 144
  • In my PHP application I send the whole content to the browser in one echo statement. There's "Transfer-Encoding: chunked" in the response headers but I'm not sending that manually. So it must be generated automatically by PHP/Apache. Is that what you mean? – batfastad Aug 22 '11 at 08:00
  • yes - that happens when either you don't provide a content-length and/or the client requests "chunked" transfer... – Yahia Aug 22 '11 at 08:01
  • And therefore I don't need to send my own content-length? After some investigation I notice that some PHP scripts send an automatically calculated content-length and others send transfer-encoding: chunked. Do you have any info as to what conditions cause PHP to send different headers? – batfastad Aug 22 '11 at 08:11
  • no - there are several factors (HTTP 1.0 doesn't support chunked), some proxies don't too, some clients don't etc. - if performance is not absolutely critical and I can calculate the content-length then I would go server-side always with content-length – Yahia Aug 22 '11 at 08:14
  • I'm not worried about the marginal decrease in performance that such a calculation would cause. How would I calculate the content-length in PHP, using strlen() on the output? We use UTF-8 throughout so I assume I DON'T want mb_strlen() because I want to know the number of bytes - not the number of characters. – batfastad Aug 22 '11 at 08:52
  • I don't know much about PHP - your question so far have been mostly about HTTP protocol... but on PHP I will have to give up... – Yahia Aug 22 '11 at 08:57