Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • William Corry 34 posts 171 karma points
    May 16, 2015 @ 11:07
    William Corry
    0

    Creating cookies for Critical CSS and fonts

    I am trying to optimize my front end code as much as possible and one thing I want to do is be able to set a cookie for people who have already visited so load the css from cache a bit like what is happening on:

    http://www.filamentgroup.com/lab/font-events.html

    in SSI they use:

    <!--#if expr="$HTTP_COOKIE=/fonts\-loaded\=true/" -->
    <html lang="en" class="fonts-loaded">
    <!--#else -->
    <html lang="en">
    <!--#endif -->
    

    Is there a way I can do something equivalent in umbraco with razor?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    May 16, 2015 @ 21:48
    Dan Diplo
    100

    You could do something like:

    @{
        var cookie = Request.Cookies["fonts-loaded"];
        bool fontsLoaded = cookie != null && cookie.Value == "true";
    }
    
    <html lang="en" @Umbraco.If(fontsLoaded, "class=\"fonts-loaded\"")>

    This assumes you have set a cookie called "fonts-loaded" with a string called "true" elsewhere.

  • William Corry 34 posts 171 karma points
    May 18, 2015 @ 17:46
    William Corry
    0

    Thanks that works perfectly :) thanks

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies