I have a website developed in Angular (SPA), for each screen I have the trigger of a DirectCall based on a layer of data. In this DirectCall I have only one action configured of the type custom code, responsible for reading the data layer, checking if it is a Custom Link Rule or Page Load Rule and redirecting to another DirectCall, that executes the trigger. But I realized that every time I call this DirectCall I have a push of the code in the DOM HTML. One or the other trigger is not a problem, but because it is a SPA, the user can accumulate many triggers by browsing the website and this will insert more and more code, becoming a problem. Is there any other way to create this router? Is there any extension that will help me with this?
Because this custom code is not embedded in the library itself (i.e. the rule isn't triggered by 'Page Top' or 'Page Bottom'), you are seeing the results of using postscribe to execute the custom code. It's also important to know that this code is executed outside of the timing control of Launch (meaning other Rules and Actions may happen before this postscribed code fully completes, yikes! ).
There's no way I could explain it better than Aaronius9er9er9er : So I'd recommend reading his post to grasp how and when postscribe is used. (link below)
If you are concerned about the code bloating the DOM, or being visible to the user; you still have plenty of options. One option would be to execute the custom code in the condition section rather than a custom code action block. Another option (especially if your goal is collecting data for analytics) would be to group this "reading the data layer" into the specific data elements you plan to use within the "Analytics Set Variables" action block.
There's no single 'best way' or 'standard way' , since all needs and implementations are different - but hopefully this opens up some new possibilities. If you know exactly what you are doing with the results, that is probably the best place to put this code in a place that's closer to it's use case (like a data element that's referenced in Set Variables).