Announcement

Collapse
No announcement yet.

OnReady ? If using multiple HTMLScriptElement ?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • CastleSoft
    started a topic OnReady ? If using multiple HTMLScriptElement ?

    OnReady ? If using multiple HTMLScriptElement ?

    Quick question..

    Say I load CSS and Javascript in the public static void Main() like the following:

    var body = Document.Body;
    var head = Document.GetElementsByTagName("head")[0];
    
    var ss = new HTMLLinkElement
    {
        Rel = "stylesheet",
        Href = "https://cdn.syncfusion.com/15.1.0.41/js/web/gradient-saffron-dark/ej.web.all.min.css",
        OnLoad = (arg) => { Console.WriteLine("*** CSS Loaded ***"); }
    };
    
    var jscript = new HTMLScriptElement
    {
        Src = "https://cdn.syncfusion.com/js/assets/external/jquery-1.10.2.min.js",
        OnLoad = (arg) => { Console.WriteLine("*** jQuery Loaded ***"); }
    };
    
    var script = new HTMLScriptElement
    {
        Src = "https://cdn.syncfusion.com/15.1.0.41/js/web/ej.web.all.min.js",
        OnLoad = (arg) => { Console.WriteLine("*** SyncFusion Loaded ***"); Doit(); }
    };
    
    head.AppendChild(ss);
    head.AppendChild(jscript);
    head.AppendChild(script);
    How can I check everything is loaded (DOM hook ? or otherwise) Without adding OnLoad events to each HMLScriptElement
    and checking if the multiple bits have loaded via a Flag ? (as the order of ss, jscript, script isn't always the same)

    Is there a generic.. OnReady I can hook if I am loading CSS/Javascript via Bridge at runtime, instead of including in the HTML ?
    It also appears to be slower than using the links directly in the HTML ?

    Any suggestions / info appreciated.

    Thanks
    Last edited by geoffrey.mcgill; 2018-02-11 @ 11:33 PM.

  • CastleSoft
    replied
    https://deck.net/eb9d5c2769ffc6a1ae489b6ef5cd475b

    [Ready]
    public static void AppStart()
    {
    Console.WriteLine("Startup");
    }
    
    public static void Loaded()
    {
    Console.WriteLine("LOADED...");
    }
    
    [Init]
    public static void LoadFiles()
    {
    Document.AddEventListener("readystatechange",x => Loaded());
    Appears to work ok ?? By adding an Event Listener for readystatechange

    Startup
    *** CSS Loaded ***
    *** jQuery Loaded ***
    *** SyncFusion Loaded ***
    LOADED...
    Last edited by geoffrey.mcgill; 2018-02-12 @ 12:43 AM. Reason: Please use [CODE] tags

    Leave a comment:


  • geoffrey.mcgill
    replied
    Thanks for the update. The static void Main method is fired based on the logic similar to the [Ready] attribute, so I guess that event is fired earlier than you require.

    https://github.com/bridgedotnet/Brid...eference#ready

    Leave a comment:


  • CastleSoft
    replied
    Thanks, Unfortunately...

    https://deck.net/4bc0dc0deb7c186626fb713c88a7299f
    • Startup
    • *** jQuery Loaded ***
    • *** CSS Loaded ***
    • *** SyncFusion Loaded ***
    The Startup (main()) still runs before the scripts have loaded. (console output order above).


    Leave a comment:


  • geoffrey.mcgill
    replied
    Maybe try adding these scripts inside an [Init] method, then your static void Main may fire after they have loaded.

    https://github.com/bridgedotnet/Brid...reference#init

    Hope this helps.
    Last edited by geoffrey.mcgill; 2018-02-11 @ 11:59 PM.

    Leave a comment:

Working...
X