Questions:
Do you really need this?
The general scheme is to send the whole js of the linked file (you can trick it, reduce it, etc.), but it will still contain the templates and the code that you implemented. In most cases, this is not a problem, because in fact there is no confidential data. The point is to properly protect REST API endpoints.
If you really wanted
You can use for example. webpack or any other binding system that allows you to create separate packages and download the correct piece of code only when necessary (for example, after successful login). Here you download async for webpack . This resource will be protected by the hosting server (an authorized user will be required - just like REST API calls).
source share