Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an API or Callback that enables developers to obtain the progress when downloading the wasm file. #1459

Open
xb284524239 opened this issue Jan 7, 2025 · 0 comments

Comments

@xb284524239
Copy link

xb284524239 commented Jan 7, 2025

💡 Feature description

Could an API or Callback be provided in the xxx.js file generated by wasm-pack packaging, allowing developers to obtain the progress when downloading the wasm file? Because the wasm files generated by projects of different sizes may be 1MB, 5MB or even 10MB. If developers cannot get the download progress, they will not be able to display a progress bar on the web page, which is not a very good experience for users in front of the computer.

The command which I used: wasm-pack build --release --target web

💻 Basic example

// index.html

<body>
    <!-- canvas required by the Slint runtime -->
    <canvas id="canvas"></canvas>

    <div id="loading">
        <p>loading...</p>
        <span id="current"></span> / <span id="total"></span> MB
    </div>
    <script type="module">
        function show_progress(current, total) {
            document.getElementById("current").innerText = (current / 1024 / 1024).toFixed(2);
            document.getElementById("total").innerText = (total / 1024 / 1024).toFixed(2);
        }

        import init, { start } from "./pkg/memlib.js";  // The memlib.js is automatically generated by wasm-pack.

        let options = {fetchProgress: show_progress, /*.. some other options */ };

        await init(options); 

        document.getElementById("loading").style.display = "none"; // Initialization completed, hide the 'loading' div

        start(); // start my program

    </script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant