jonathantneal / http-client-hints

Hurray for server-side content negotiation
Other
126 stars 7 forks source link

Cookies not send for initial requests #2

Open nothrem opened 9 years ago

nothrem commented 9 years ago

Browsers (tested in FF41 and IE11; Chrome already support Client Hints) does not send new cookies created while parsing HTML until the HTML is fully processed.

When new cookies become included in requests:

  1. create new cookie in inline script
  2. load CSS in header -> does NOT contain new cookie
  3. load JS in header -> does NOT contain new cookie
  4. load JS in body -> does NOT contain new cookie
  5. [finished processing HTML code]
  6. load images and other files -> contains new cookie
  7. [page is completely loaded]
  8. load CSS or JS dynamically added into header -> contains new cookie
  9. load CSS or JS via ajax -> contains new cookie

You would need to reload the page after creating new cookie to force all requests to send it.

<?php if (!isset($_SERVER['HTTP_CH'])) : ?>
    <script>document.cookie = ...; location.reload();</script>
<?php endIf; ?>
geeky-biz commented 5 years ago

When I include a couple of images in a simple HTML page - I see that these image requests do not contain the new cookie. They do so only on reload. So - yes - this is to confirm that until HTML is parsed, cookie headers are not sent with image requests.