Site logo

[Support request] Clear users’ browser cache?

Home Forums Support [Support request] Clear users’ browser cache?

Home Forums Support Clear users’ browser cache?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2497780
    Kip

    Hi,
    When using a style.css registered to WordPress via functions.php, it was possible to clear users’ browser caches using a version number, ie:
    style.css?version=1.0, and then upping the version number to force visitors’ browsers to update to the latest version.
    Is this possible with GeneratePress other than to start messing with the parent theme? Using a child them, without any registered css files at the child level, and not sure how to force a refresh.
    Afraid I’ve been doing some fine tuning on the site, and want to be sure that users are getting the latest version.
    Thanks!

    #2497864
    Ying
    Staff
    Customer Support

    Hi Kip,

    This is not something that a theme can control, unfortunately.

    I would recommend reaching out to cache plugins’ support to see if they have some insights.

    #2497906
    Kip

    Ok thanks maybe I’m not making myself clear – it’s very much something a theme can control, just by adding a version number to the style.css registration, like this:
    (just an example)
    wp_enqueue_style( ‘custom-style’, get_template_directory_uri() . ‘/css/custom-style.css?version=1.1′ );
    Changing the version number of the style will force browsers to reload the style instead of using the locally cached one.
    This is not a matter of cache plugins, the caching is happening in end users’ browsers.
    Since there’s no stylesheet enqueued in the child theme, I don’t have access to changing version numbers and am wondering if there’s another way to force update end users stylesheets (I’m gathering that there’s not).

    kip

    #2498281
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Which files are you wanting to add a version number to?

    If you’re using the child theme style.css file, you can see here that GeneratePress uses filemtime(): https://github.com/tomusborne/generatepress/blob/3.2.4/inc/general.php#L67

    This function will get the date the file was last changed and convert it to a number, then append it to the child theme stylesheet. This should tell the browser to reload the file whenever the file is changed.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.