Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1265380

    Hi guys
    I know how to upload an icon font to the site ( following these instructions ), but if we later add more icons to a custom icon set I can’t find a way to version this so that users don’t have to clear their cache to see the new fonts. For example:

    • I add a font called “my-font” downloaded from fontello
    • A user visits my site. The font files are static assets so the user’s browser caches the asset
    • A month later I add a new icon to the font. I re-generate the package and re-upload
    • When the same user visits my site they will not see the new icon because the browser uses the cached version. We use a strong cache policy so these static assets have a max-age value of 31536000 which is one year.

    If I generate the font using something like Icomoon it adds a version to the JSON file, but this seems to be ignored. I can’t simply change the font name because all my existing icons will break. Is the only solution here to upload a new font pack that only includes the new icons?

    #1265659

    Hey guys

    Just following up on this, I noticed in the source code that from lines 527 – 534 of config-templatebuilder/avia-template-builder/php/font-manager.class.php there is an “append” variable. Would be great if this were filterable or able to be set somewhere via the UI when adding a font.

    #1266930

    Hi,
    Sorry for the very late reply, unfortunately when a static resource is cached by the users browser, it is necessary for the cache to be cleared to show an updated version of the same item.
    For this situation, I would recommend changing the name of the font package at fontello and only include the new icons each time you change them.
    By changing the name of the font package the font used will be different so the browser will consider it a new resource and download it, and ignore the cached version.
    I believe that the thought behind no versioning for icon fonts is that it was not expected that the same icons would be changed often, do you plan on changing them often? Is it something like monthly scheme changes?

    Best regards,
    Mike

    #1266943

    Hi Mike

    Thanks for your reply, although I’m very much aware of how a browser caches static resources. One of the most common ways to clear the cache of static resources is to serve them with a version number, this is exactly what WordPress does natively when you use wp_enqueue_script and specify a version number. It appends a “?v=xyz” onto the url. For example, when I load a stylesheet with a version it becomes https://www.example.com/wp-content/themes/some-theme/styles.css?v=1.0.0 then when I update the version number it becomes https://www.example.com/wp-content/themes/some-theme/styles.css?v=1.0.1, the browser sees it as a new resource and I don’t have to specify styles-1.css or styles-2.css as that would be ludicrous and you’d end up with a new asset every time you made an update. Terrible on so many levels, especially SEO ( imagine having to download 30 different external resources after 30 different updates! ).

    Likewise for font files, I’ve noticed that what Enfold does is take the name of the font ( let’s say it’s called “my-font” ) takes the assets out of the zip file and uploads them to uploads/avia_fonts/my-font/my-font.woff. So then when it requests this resource the filename is always the same and as such the browser caches it. A simple way to get around this would be to append a query parameter onto the end that can be changed when the font changes. It would make sense to keep using ?v=xyz as that’s what WordPress does natively.

    As per my previous message I’ve noticed that Enfold also uses the “append” property from the array stored in the options table. Although this append property is not editable directly. At the very least if we could have this passed through a filter, developers could add their own parameters here and bust the cache ourselves, which would mean you don’t have to do hardly any work to get it working and we can still optimise our font files. A simple one-liner would suffice. Insert this after config-templatebuilder/avia-template-builder/php/font-manager.class.php line 509

    $append = apply_filters('avf_font_append', $append, $font_name, $font_list);

    As for the solutions you suggested, they could work but there are a few issues. Firstly, if I create a new icon set with only the new icons whenever they change:
    1. it creates a messy experience for the web admins and content editors as there could potentially be many different sections of fonts. E.g. My Font 1, My Font 2, My Font 3
    2. it means that the browser has to load a new external resource every time we want to add a new icon. Definitely not ideal for page speeds. More external requests = longer page loads. Sure, they’ll be small, but it’s way better to load 1 file than three small ones if we can.

    If I were to simply change the name of the icon set and include all the icons, it breaks all the existing icons and we have to go through and re-assign all of them, this is really not ideal.

    If we could really just get that one filter added it would be super helpful and it’s barely any work for the devs your end to implement. There’s already a filter in there for the font_display, why not extend that for the append parameter too?

    Cheers

    #1266953

    Hi,
    Thank you for the feedback, I suppose if you are going to be changing your icon fonts often my suggestion would be a hassle considering your cache is set for a year.
    I have submitted this request to the dev team for review, when the dev team replies I will post it here. Thank you for your patience.

    Best regards,
    Mike

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