- Home
- Forum
- ASP.NET Core - EJ 2
- ejs script reference using async or defer mode
ejs script reference using async or defer mode
Hi, Vairamuthu Ramamoorthi
Even after using CRG Syncfusion.js file size is 3.5MB and that must loaded in <head> that blocks page loading and on slow internet it can take too much time that give negative impact on Application.
Even I have tried defer loading with
<ejs-scripts defer></ejs-scripts> but Script Manager executes immediately before loading the script that is quite annoying. Is there any ways execute script manager on
DOMContentLoaded Event?
Hi Khalid Mahmood,
Since <ejs-scripts> renders content from the server, it expects the ejs library to be fully loaded on the client side before executing. This dependency means that using async or defer on the ejs script tag can cause timing issues, where ScriptManager executes before ejs is available, resulting in the ejs is undefined error.
Why async and defer Don’t Work Here
- Async loads the script independently and executes it as soon as it’s downloaded, which may happen after the ScriptManager starts running.
- Defer ensures the script loads after HTML parsing, but it may still not load in time for ScriptManager if there are network delays or a large file size.
Solution for Faster Loading
- Use the Syncfusion CDN: Loading ejs from Syncfusion’s CDN can improve performance by leveraging a distributed network of servers, ensuring faster delivery of the script without needing async or defer.
<script src="https://cdn.syncfusion.com/ej2/27.1.55/dist/ej2.min.js"></script>
- Generate Component-Specific Scripts via CRG: To further reduce load times, use the Custom Resource Generator (CRG) to create smaller, component-specific scripts. This approach decreases the initial script size, improving page load times without causing timing conflicts with ScriptManager.
- CRG resources:
Regards,
Arun Kumar R
@Arun Kumar Ragu
Is there any option to load Independent Component from CDN like I only want to RTE on page. because complete file is 23MB from CDN and CRG file again included manually.
Hi Khalid Mahmood,
We suspect that you might have referred both the CDN and the CRG-generated file. Kindly ensure that you are using only one of these. The CDN includes scripts for all Syncfusion components, whereas if you need only the RTE component, you can use the CRG (Custom Resource Generator) to download the script specifically for RTE.
For more details, please refer to the documentation linked below.
https://ej2.syncfusion.com/aspnetcore/documentation/common/custom-resource-generator
https://ej2.syncfusion.com/aspnetcore/documentation/common/adding-script-references
Regards,
Arun Kumar R
- 7 Replies
- 5 Participants
-
MA Mani
- Apr 19, 2019 06:05 AM UTC
- Nov 25, 2024 01:42 PM UTC