• Resolved graf1n

    (@graf1n)


    Hello!
    I include CSS styles in functions.php depending on cookies. How can I prevent the css block <link rel = “stylesheet” href = “/ wp-content / themes / flatsome-child / customstyles.css” /> from being cached?

    Included ESI, tried different markup in html, but it doesn’t work.

    I connect CSS like this:
    if ($ tempBlock == 1)
    {

    add_action (“wp_head”, “wp_head_extra_code”);
    function wp_head_extra_code () {echo ‘<link rel = “stylesheet” href = “/ wp-content / themes / flatsome-child / customstyles.css” />’;
    }

Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Support Hai Zheng?

    (@hailite)

    If its just to simply exclude the pages containing that CSS from cache, you can append no cache api call in your function wp_head_extra_code.
    e.g. in v3, you can use:

    
    function wp_head_extra_code () {
               do_action( 'litespeed_control_set_nocache' );
               echo ‘<link rel = “stylesheet” href = “/ wp-content / themes / flatsome-child / customstyles.css” />’;
    }
    
    Thread Starter graf1n

    (@graf1n)

    Probably not correctly explained.
    I need code not to be cached on all pages:
    <head>
    ?? <link rel = “stylesheet” href = “animations.css”> </link>
    ?? <link rel = “stylesheet” href = “common.css”> </link>
    </head>

    I include CSS by condition in functions.php

    Probably it’s good for me to disable caching for the whole file /wp-content/themes/flatsome-child/header.php

    • This reply was modified 4 years, 7 months ago by graf1n.
    • This reply was modified 4 years, 7 months ago by graf1n.
    Thread Starter graf1n

    (@graf1n)

    It is necessary to turn this piece of code from header.php into an ESI block and not cache it

    <head>
    	<meta charset="<?php bloginfo( 'charset' ); ?>" />
    	<link rel="profile" href="https://gmpg.org/xfn/11" />
    	<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
    
    	<?php wp_head(); ?>
    
    </head>

    Or disable caching wp_head ();

    • This reply was modified 4 years, 7 months ago by graf1n.
    • This reply was modified 4 years, 7 months ago by graf1n.
    Plugin Support Hai Zheng?

    (@hailite)

    Will you give this block a separate cache per user or group? I asked bcos if you set it to ESI and no-cache, and if it goes through WP’s init logic, this will cause the parent page slow and equals no cache even parent page is cached.

    Thread Starter graf1n

    (@graf1n)

    I enable CSS based on cookie records. I need the whole <head> </head> block or wp_head (); not cached

    for each user

    • This reply was modified 4 years, 7 months ago by graf1n.
    • This reply was modified 4 years, 7 months ago by graf1n.
    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    Please check this wiki , it is an example for how to make ESI block.

    Best regards,

    Thread Starter graf1n

    (@graf1n)

    Thank you! Where to get version v3.0 rc 10 or later.

    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    Please check this post

    Best regards,

    Thread Starter graf1n

    (@graf1n)

    Updated to v3.0.0-rc12
    In header.php added

    <div>
    apply_filters ('litespeed_esi_url', 'my_esi_block', 'Custom ESI block');
    </div>

    in functions.php added

    add_action ('litespeed_esi_load-my_esi_block', 'my_esi_block_esi_load');
    
    function my_esi_block_esi ()
    {
    do_action ('litespeed_control_set_ttl', 0);
    echo rand (1,99999);
    }

    Doesn’t work, what am I doing wrong? Took all of the above example

    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    By doesn’t work , is it doesn’t show up at all ? or it is not randomized number but show one fixed number ?

    Best regards,

    Thread Starter graf1n

    (@graf1n)

    the string is displayed as is

    <div>
    apply_filters ('litespeed_esi_url', 'my_esi_block', 'Custom ESI block');
    </div>

    Not processed

    Thread Starter graf1n

    (@graf1n)

    Added like this (header.php):
    <?php echo apply_filters( 'litespeed_esi_url', 'my_esi_block', 'Custom ESI block' ); ?>

    The following code appears:

    </style><!-- lscwp Custom ESI block --><esi:include src='/en/?lsesi=my_esi_block&_control=private%2Cno-vary&_hash=d2c672b3d393ce5091e81c7b78816030' cache-control='private,no-vary' /><!-- lscwp Custom ESI block esi end --></head>
    

    How can I derive rand ();

    • This reply was modified 4 years, 7 months ago by graf1n.
    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    Apologize for the inconvenience.

    There was some typo in that wiki , please check it again , I update it with your example code.

    Best regards,

    Thread Starter graf1n

    (@graf1n)

    I did everything from the wiki.
    <!-- lscwp Custom ESI block --><esi:include src='/ru/?lsesi=my_esi_block&_control=private%2Cno-vary&_hash=d2c672b3d393ce5091e81c7b78816030' cache-control='private,no-vary' /><!-- lscwp Custom ESI block esi end -->

    How to derive the value itself instead of this code? Hello world31636

    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    I am sorry , I didn’t understand your question.

    Best regards,

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘How to exclude cache’ is closed to new replies.