This post is taken form a comment of mine on card-mod GitHub issue [HACS]: CARD-MOD (4.2.0): hui-card already patched by 4.2.0! · Issue #582 · thomasloven/lovelace-card-mod · GitHub and modified to suit forum.
Below I include some discussions on caching, a general section on Home Assistant ‘Frontend’ caching, a Performance improvement timeline which highlights investigative work on how duplicate patching gives rise to card-mod issues, and a FAQ to answer some common questions on the topic and how it my be improved.
While I am a contributor to Home Assistant custom cards and integrations, I also run Home Assistant for my home with other non-technical Apple iOS Companion App users, including using my own iOS devices with Companion App.
With respect to caching, especially for Companion App, if you follow the card-mod recommendations, you should not get future warnings after upgrade. However, as caching is a detailed topic, your environment may give rise to scenarios needing more attention.
The card-mod upgrade process I use is as follows. With this my home users do not generate any warnings. I use HACS and extra_module_url.
-
Upgrade via HACS. If you say yes to reload you will get one warning as already the Resource URL is different. I generally do reload and go and dismiss the notification. This confirms that HACS has loaded the updated card-mod correctly.
-
Straight away without delay, get Dashboard resource URL and update configuration.yaml
extra_module_urlfor card-mod. -
Restart Home Assistant.
Home Assistant ‘Frontend’ caching
Home Assistant uses a service worker that uses Browser cache storage. It calls the Cache storage file-cache (there are some others as well). This is not to be confused with the Browser’s general cache which will still be used if a request is not in file-cache. I have included a screenshot below to show how you can review what is in this cache. These are the caches that the new card-mod clear_cache action clears, and also these same caches are also cleared (as well as localStorage etc.) when you use the Troubleshooting section of Companion App.
Next, Home Assistant also uses a single page style architecture, updating the relevant sections when you go to different views/dashboards. So when you first go to say ‘/lovelace’ (open Companion App after some time, reload page on desktop etc.) it will get the html file served at that url. When you then view a different dashboard, no new html file is retrieved, Home Assistant replaces the view, depending on what it is. e.g. when you go to a different dashboard, a new lovelace panel will be created by partial-panel-resolver, swapping out the previous lovelace panel. You can review this by manually clearing the file-cache using Browser developer tools, browse some Dashboards, and see that the only Dashboard url in the file-cache will be the one you started on.
Next, for resources, those which are Dashboard resources are handled dynamically, and will be refreshed and loaded asyc by document <script> tags, a separate one for each script. However those loaded by extra_module_url are concatenated together in one JS script file in browser <head>. (Aside, this is also why if one extra_module_url causes a load error, all may be affected).
Noting here that a Browser will NOT load any JS file again that has the EXACT same URL including search tags (hacstag etc.), but WILL load a JS file again if it IS a different URL - the Browser has no knowledge of what the file is by URL so just blindly thinks it is different and needs to load it.
Following on, Home Assistant only updates the extra_module_url section of the page served after restart. There are scenarios here were the initial dashboard page in file-cache is used and not refreshed from Home Assistant. This is the the scenario that then needs manual intervention on the Browser/device. My understanding of what happens here is based on findings to get Browser Mod integration to the point it knows the Dashboard page in file-cache is out of date, and is possibly where further improvements with card-mod and/or Home Assistant can be made. Thinking of improvements for card-mod, I am not sure if this would be possible without a ‘master’ telling the Browser what card-mod version it should be running. In Browser Mod case the integration (backend) knows the version and tells Frontend JS what to expect, and if not that version, to put up a toast prompt to reload. This would be the aim for card-mod in some way - perhaps using HACS integration call if available, or the update sensors HACS creates, using it as ‘master’ version.
Performance improvement timeline
-
Around June/July 2025 I started to investigate why users were getting Performance warning issue, weird errors etc. that could not be put down to any bugs/issues.
-
On investigation I found that Browsers will indeed load JS files twice if not exact matching URL. No glitch here, this is 100% true, tried and tested.
-
I started to assist users who were having strange issues, card-mod’s working/not on page refresh etc, to make sure their URLs matched and users were finding this fixing their issues. (Particularly in v3.x where duplicate patching actually run duplicate code, hence the loss of card_mod in visual editor for entities, for example, due to the patching code actually running twice).
-
I was able to become a contributor/maintainer for card-mod (thanks Thomas) and so went about on the journey to rectify this issue.
-
First, v4.0.0 stopped duplicate patching code running, though as card-mod is only Frontend, whatever is loaded first ([cached version] of extra_module_url) wins out (with any 3.x versions at this time still merrily doing like they did before, causing duplicate patching issues).
-
This helped, though assisting users through 4.1.0 and 4.2.0 beta periods, it was clear that there were still incorrect configs, and it was hard to tell what was what as which ever version is loaded as a module, and could be a previous 4.x cached version, will run the pactching code, with old code being run, even though users have updated to the latest version.
-
Come along 4.2.0, and the duplicate patching introduced tracking version along with the console and Frontend notification warning and updated README.
FAQ
Why have this (annoying) warning?
This is a good question and everyone wishes to not have irrelevant warnings. Using the case of a Cloudflare issue noted in the GitHub thread, it shows it does matter, even if the version is the same. So knowing there is an issue to fix means first making sure that is addressed before chasing issues further down rabbit holes, when the issue all along is duplicate card-mod resources running.
Can this be better?
Yes, indeed. Possible improvement would be for card-mod to know the ‘master’ version and then prompt for cache refresh like Browser Mod. It’s a point in time to work out the best way for card-mod to know the ‘master’ version for the Home Assistant setup. This could be done by making card-mod an integration with a backend part to handle versioning etc. Then in effect it would become like Browser Mod in the way it manages its resources. The other way would be to use HACS, if available, to query the card-mod ‘master’ version and for the Frontend to handle appropriately. I will likely go this path first as it is much easier and if works, will be non breaking, non impacting and hopefully get to a much better position. If anyone reading this thinks they can code this approach, please do so and submit a PR.
Do I not get what warnings etc mean for admins and their users?
I 100% get it. I have non-technical users in my household. This issue is a journey and hope to get it even further improved. Having issues solved by knowing it is duplicate patching, rather than chasing otherwise, gives me more time to get this duplicate resource issue to a better point, as well as more time for new features and other improvements.
Does card-mod need more contributors (Dorothy Dixer here)?
Absolutely. There may have been a period when contributors got tired as reviews were not happening. Should any contributor wish to contribute a PR I am ready to review without delay.
