Skip to content

Comments

docs: Add guide for CDN and dynamic JavaScript loading in WebAssembly apps#22272

Closed
Copilot wants to merge 3 commits intomasterfrom
copilot/add-js-references-to-wasm
Closed

docs: Add guide for CDN and dynamic JavaScript loading in WebAssembly apps#22272
Copilot wants to merge 3 commits intomasterfrom
copilot/add-js-references-to-wasm

Conversation

Copy link
Contributor

Copilot AI commented Jan 6, 2026

PR Type:

📚 Documentation content changes

What is the current behavior? 🤔

No documentation exists explaining how to load JavaScript from CDN or dynamically at runtime in Uno Platform WebAssembly applications. The existing Part 1 walkthrough covers basic embedding with WasmScripts and wwwroot folders, but doesn't cover CDN loading or advanced dynamic loading scenarios.

What is the new behavior? 🚀

Added focused guide complementing the existing Part 1 walkthrough, covering advanced JavaScript loading methods:

New Documentation: wasm-referencing-js.md (215 lines)

  • CDN Loading Methods

    • Three options: index.html, dynamic JS loader, AMD/RequireJS
    • Version pinning strategies
    • Fallback to local copies with onload/onerror handlers
  • Dynamic Runtime Loading

    • Using WebAssemblyRuntime.InvokeJS for runtime script loading
    • Conditional loading example with proper using statements (load scripts only when needed)
  • Best Practices

    • Version pinning to avoid breaking changes
    • Fallback strategies for CDN failures with proper onload handlers
    • Security considerations (SRI, CORS)
  • Troubleshooting

    • Script loading issues
    • Load order problems
    • CORS issues with CDN

Navigation Updates:

  • Added to toc.yml under "Embed a JavaScript Component" section
  • Cross-referenced from existing wasm-javascript-1.md with NOTE box

Document explicitly references Part 1 for fundamentals to avoid duplication with existing walkthrough covering WasmScripts, WasmCSS, and basic wwwroot usage.

Example usage:

// CDN loading via AMD/RequireJS
var javascript = @"require(['https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js'], 
    function(_) {
        console.log('Lodash loaded:', _.VERSION);
    }
);";
WebAssemblyRuntime.InvokeJS(javascript);

// Dynamic conditional loading with proper using statements
using Microsoft.UI.Xaml.Controls;
using Uno.Foundation;

public static void LoadScript(string url)
{
    var javascript = $@"
        (function() {{
            const script = document.createElement('script');
            script.src = '{url}';
            script.async = true;
            document.head.appendChild(script);
        }})();
    ";
    WebAssemblyRuntime.InvokeJS(javascript);
}

PR Checklist ✅

  • 📝 Commits follow Conventional Commits specification
  • 🧪 Runtime tests, UI tests, or manual test sample added (N/A - documentation only)
  • 📚 Docs added/updated following documentation template
  • 🖼️ Validated PR Screenshots Compare Test Run results (N/A - documentation only)
  • ❗ Contains NO breaking changes

Other information ℹ️

Documentation simplified based on feedback to avoid duplicating content from the existing Part 1 walkthrough. The guide now focuses exclusively on CDN loading, dynamic loading, and best practices - serving as a complement to the existing documentation rather than a replacement.

Review feedback addressed:

  • Removed complex JSImport examples that required additional setup
  • Simplified to use only WebAssemblyRuntime.InvokeJS approach throughout
  • Added proper using statements to all code examples for clarity
  • Added onload handler to fallback strategy example to properly handle success cases
  • Removed all duplication with existing Part 1 walkthrough
Original prompt

This section details on the original issue you should resolve

<issue_title>[WASM] Explain how to reference arbitrary .js scripts</issue_title>
<issue_description>### What would you like clarification on? 🤔

Currently we don't have documentation on how to reference arbitrary .js libraries/scripts within WebAssembly apps

Concern 📚

None

Renderer 🎨

  • Skia
  • Native

Affected platforms 📱💻🖥️

No response

Any feedback? 💬

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…M apps

- Add new wasm-referencing-js.md with detailed guide on all methods
- Update toc.yml to include new documentation page
- Update wasm-javascript-1.md with cross-reference to new guide

Co-authored-by: Jen-Uno <214558326+Jen-Uno@users.noreply.github.com>
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI changed the title [WIP] Add documentation for referencing arbitrary JS scripts in WASM docs: Add comprehensive guide for referencing JavaScript files in WebAssembly apps Jan 6, 2026
Copilot AI requested a review from Jen-Uno January 6, 2026 16:19
@github-actions github-actions bot added area/build Categorizes an issue or PR as relevant to build infrastructure kind/documentation labels Jan 6, 2026
@Jen-Uno Jen-Uno requested a review from MartinZikmund January 6, 2026 16:22
@Jen-Uno Jen-Uno marked this pull request as ready for review January 6, 2026 16:38
Copilot AI review requested due to automatic review settings January 6, 2026 16:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive documentation explaining how to reference and load JavaScript files in Uno Platform WebAssembly applications. The documentation addresses a gap where developers previously had to piece together information from multiple sources.

Key Changes

  • New comprehensive guide (wasm-referencing-js.md) covering four methods for loading JavaScript in WASM apps: embedded local scripts, static web assets, external CDN scripts, and dynamic runtime loading
  • Navigation updates to integrate the new documentation into the table of contents under the "Embed a JavaScript Component" section
  • Cross-references added to existing JavaScript interop documentation for improved discoverability

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
doc/articles/interop/wasm-referencing-js.md New 450-line comprehensive guide covering all JavaScript loading methods with code examples, best practices, security considerations, and troubleshooting
doc/articles/toc.yml Added navigation entry for the new guide under "Embed a JavaScript Component" section
doc/articles/interop/wasm-javascript-1.md Added cross-reference tip boxes pointing to the new comprehensive guide

@unodevops
Copy link
Contributor

⚠️⚠️ The build 190071 has failed on Uno.UI - docs.

Remove duplicated content about WasmScripts, wwwroot folders, and basic embedding that's already covered in wasm-javascript-1.md. Focus on CDN loading, dynamic loading, best practices, and troubleshooting.

Co-authored-by: jeromelaban <5839577+jeromelaban@users.noreply.github.com>
Copilot AI changed the title docs: Add comprehensive guide for referencing JavaScript files in WebAssembly apps docs: Add guide for CDN and dynamic JavaScript loading in WebAssembly apps Jan 6, 2026
Copilot AI requested a review from jeromelaban January 6, 2026 17:08
@Jen-Uno Jen-Uno removed their request for review January 6, 2026 17:15
@unodevops
Copy link
Contributor

⚠️⚠️ The build 190081 has failed on Uno.UI - docs.

@Jen-Uno Jen-Uno closed this Jan 6, 2026
@Jen-Uno Jen-Uno deleted the copilot/add-js-references-to-wasm branch January 6, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/build Categorizes an issue or PR as relevant to build infrastructure kind/documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[WASM] Explain how to reference arbitrary .js scripts

5 participants