like HT Script application( https://apps.shopify.com/ht-script )。you can add custom script like
"var a=1";
and we can see custom script in html header like
<script>var a=1;</script>
i know Shopify API support script tag to add custom script like
<script src="http://xxxx.js"></script>
so,what's the principle behind HT Sciprt application,why it don't need src 。
App has following permissions:
That means it uses following access scopes
Way how it probably works
Reads list of themes
GET /admin/api/2021-01/themes.json
With that list it can find active theme.
Field "role" equals "main".
With active theme id it can access assets.
GET /admin/api/2021-01/themes/{theme_id}/assets.json?asset[key]=layout/theme.liquid
With content of that file you can modify headers as you want with html parser.
Update the same file with another api call
PUT /admin/api/2021-01/themes/{theme_id}/assets.json
Of course you can create some cron job in your application to make sure that your modified scripts are always up to date with template.
Helpful links: