CUTCODEDOWN
Minimalist Semantic Markup

Welcome Guest
Please Login or Register

If you have registered but not recieved your activation e-mail in a reasonable amount of time, or have issues with using the registration form, please use our Contact Form for assistance. Include both your username and the e-mail you tried to register with.

Author Topic: How do HTTP servers using HTTP 2.0 know which items to push?  (Read 946 times)

gleepower

  • Junior Member
  • *
  • Posts: 22
  • Karma: +1/-0
One of the benefits to http server push as I understand it in http 2.0 is that rather than creating lots of TCP connections with fetching different stylesheets and images, you can instead create just one TCP connection and have the server dump all the required stylesheets and images.

How does the server know which stylesheets/images/scripts to push for a given HTTP request though? Does the server look at the HTML markup and magically work it out? Or do you have to manually set this up.
The beaucracy is expanding, to meet the needs of the expanding beaucracy

Jason Knight

  • Administrator
  • Hero Member
  • *****
  • Posts: 1060
  • Karma: +188/-1
    • CutCodeDown -- Minimalist Semantic Markup
Re: How do HTTP servers using HTTP 2.0 know which items to push?
« Reply #1 on: 16 Nov 2019, 12:10:07 pm »
You send a "Link:" in the http headers. If you're using PHP this is easily done with the header() command, or you could add it to certain files via the .htaccess method.

Code: [Select]
header('Link: </template/screen.css>; rel=preload; as=style, </scripts/library.js>; rel=preload; as=script, <template/images/h1Logo.png>; rel=preload; as=image');

for example.

If you were doing it in httpd.conf or .htaccess:

Code: [Select]
<FilesMatch "\.php$">
    Header add Link "</template/screen.css>; rel=preload; as=style"
    Header add Link "</scripts/library.js>; rel=preload; as=script"
    Header add Link "</template/images/h1Logo.png>; rel=preload; as=image"
</FilesMatch>

So it doesn't just "know", you have to tell it.

BEWARE it's possible to push things that aren't actually used, and that can waste bandwidth and have a negative impact on performance. Likewise as these end up in the HTTP headers they can have the same negative impact as excessive numbers of cookies if you go overboard with it, so "good practice" is to limit yourself to EIGHT files to be pushed.

Though really if you have more than 8 files you would see benefit from pushing, there's probably something wrong with how your page is built. (see bootcrap, jquery)

Actually, that's a good one for the snippets section, my PHP code to let people make manifests that can be turned into a header().
We are all, we are all, we are all FRIENDS! For today we're all brothers, tonight we're all friends. Our moment of peace in a war that never ends.

gleepower

  • Junior Member
  • *
  • Posts: 22
  • Karma: +1/-0
Re: How do HTTP servers using HTTP 2.0 know which items to push?
« Reply #2 on: 17 Nov 2019, 08:11:13 am »
Ah that makes a lot of sense, thanks! Nice and straightforward as well.
The beaucracy is expanding, to meet the needs of the expanding beaucracy

 

SMF spam blocked by CleanTalk

Advertisement