I'm working on an app that creates some metafields and then uses those to add some markup to a page. I've read that if you can avoid editing a customer's theme that is the better route to go. Once my backend app has created the metafields is it possible within a front end JS script tag to read from those metafields?
Right now my plan is just to do this in the liquid (as is shown in all of the tutorials) but I think it would be cleaner to do this in a ScriptTag. ScriptTags are automatically removed when your app is uninstalled, however because store access is removed immediately when a customer uninstalls there is no possible way to clean up their theme to remove the line I added if I do this in liquid.
When a theme renders, that is the time to render the metafields. If your use of the ScriptTags is simply to render HTML based on the content of the metafields, you have a good chance using a not too bad pattern of use:
So if the customer removes the App, the rendering of the metafields is harmless. Only if the ScriptTag is present (App installed) would you have that ScriptTag do things to the merchant theme.