Check if a cookie exists using Jekyll Liquid

I'm using Jekyll and setting a cookie as a check to see if critical and asynchronous loaded CSS should be served to the user, so only early visitors get the critical and asynchronous CSS. I am using Filament Groups Enhance.js which sets a cookie and takes over the loading of the async CSS. What I'm trying to do is check if a cookie exists using Jekyll Liquid, but doesn't have much luck, in my main layout, I have code like this:

{% if cookie.name == fullcss %}
  <link rel="stylesheet" href="/css/style.css">
{% elsif page.section == 1 %}
  <style>
    {% include critical-css/getting-started.css %}
  </style>
  <script>
    {% include js/enhance.js %}
  </script>
  <noscript>
    <link rel="stylesheet" href="/css/style.css">
  </noscript>
{% elsif page.section == 1 %}
  ...

      

This is mainly the technique I am trying to achieve: http://iamsteve.me/blog/entry/using-cookies-to-serve-critical-css-for-first-time-visits , but I cannot use PHP as I am on the Jekyll site hosted in the GH pages.

+3


source to share


1 answer


I don't have the reputation to post this as a comment. Since this is not a direct answer, it would be preferable. I think you could do this with SSI (server aware).

I was reading this article https://www.filamentgroup.com/lab/font-events.html and noticed that it is implemented using SSI.



More information can be found here: https://www.w3.org/Jigsaw/Doc/User/SSI.html#cookie

I am not familiar with the process of this and it has been a long time since this was answered, so hopefully this may be of some help. If someone more knowledgeable could improve my answer that would be great.

0


source







All Articles