irigsoft Posted June 15, 2025 Posted June 15, 2025 Hi, I'm trying to do some loading optimizations and I want to apply some of the methods described on this link. https://www.geeksforgeeks.org/javascript/dom-loading-issues-with-javascript/ 1. all MainForm.Script 2.all unigui js files like <script src="/ext-7.4.0/build/classic/theme-neptune/theme-neptune.js"></script> <script src="/ext-7.4.0/build/ext-all.js"></script> and all other or use pre like this example: <link rel="preload" href="important-js.js" as="script" /> https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Performance/JavaScript 3. all scripts loaded from file like that : <script src="/MyCustomfiles/MyCustom.js" defer=""></script> to set defer to script on point 3 I use: UniAddJSLibrary('/MyCustomfiles/MyCustom.js', False, [upoPlatformBoth, upoDefer]);//upoAsync]); on TUniServerModule.UniGUIServerModuleCreate. How to apply to point 1 and point 2 ? Solutions to Fix DOM Loading Issues: Place Your Scripts at the End of the Body: This is the most common solution. By placing your JavaScript at the end of the <body>, it ensures the DOM is fully loaded before any scripts are executed. <body> <!-- HTML content here --> <script src="your-script.js"></script> </body> Use defer or async Attribute in Script Tags: If you need to include your script in the <head> section, use the defer attribute. This ensures that the script is executed only after the HTML document has been completely parsed. <head> <script src="your-script.js" defer></script> </head> Alternatively, use async if you want the script to load in parallel with HTML parsing but don’t care when it executes (not recommended for DOM manipulation). <script src="your-script.js" async></script> Quote
irigsoft Posted October 10, 2025 Author Posted October 10, 2025 So, no answer! But new question is here: Is it possible (and how) to add async or crossorigin when add user script ? like example: <script src="https://connect.facebook.net/en_US/sdk.js?hash=5810.....b60b045e3.......4" async="" crossorigin="anonymous"></script> Quote
Hayri ASLAN Posted October 10, 2025 Posted October 10, 2025 6 hours ago, irigsoft said: So, no answer! But new question is here: Is it possible (and how) to add async or crossorigin when add user script ? like example: <script src="https://connect.facebook.net/en_US/sdk.js?hash=5810.....b60b045e3.......4" async="" crossorigin="anonymous"></script> You have 2 options either use servermodule.custommeta to add your script directly like "<script src="your-script.js" defer></script>" or use UniAddJSLibrary('YOUR_JS_URL', True, [upoPlatformBoth, upoAsync, upoDefer]); 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.