What is Custom Action?
Custom action fetches an external script and includes it in the page. So at run time the script will self execute as an anonymous function.
Following are few scenarios you may need this functionality in your SharePoint Projects:
1) Override the new sub site link (https://tenant.) under Site Contents with your site provisioning app URL
2) Redirect the user to specific page
4) Add dynamic html (global navigation / company copy rights information on the bottom of your page) content on your sharepoint page at run time without even modifying the actual master page.
In the below example, I have explained how to inject Jquery file to one of my web. The source files can be placed in CDN / File Share / Common Location such as App Catalog.
Please feel free to change the logic as per your requirement.
Note: The logic remains same for JSOM code also.