Changing shell.html without re-linking everything?

17 views
Skip to first unread message

Phil Endecott

unread,
Jun 26, 2026, 2:53:37 PM (6 days ago) Jun 26
to emscripte...@googlegroups.com
Dear Experts,

I compile my source files to .o object files and then link with
something like:

emcc -O3 --preload-file foo.dat --shell-file shell.html abc.o def.o
ghi.o -o out.html

If I've only changed shell.html or foo.dat, can I avoid re-linking?
Since there is a lot of link-time optimisation going on, linking is
slow. I'd like to avoid that when it's not needed.

I'm wondering if there is some way to link the object files and do
the link-time optimisation, and then in a further step add the
preload files and shell.html to make the final outputs.

Ideas anyone?


Thanks, Phil.




Sam Clegg

unread,
Jun 26, 2026, 4:41:39 PM (6 days ago) Jun 26
to emscripte...@googlegroups.com
I did add an option called `--post-link` which could be just what you want here.   It lets you pass an already-linked wasm file to `emcc` instead of object files.  So you would run your build once as above and then for followup builds you could pass the `--post-link foo.wasm` instead of the object files.  This a lesser used option though, so you could run into issues with it.

Having said that, I would recommend against using `--shell-file` unless ou have a really good reason too.   Its normally easier to have emcc project a `.js` file and then have a fixes `.html` file checked in for you app.  

Likewise, do you really need to use `--preload-file`?  In most cases I recommend using `--embed-file` (unless you really want to deploy your data separelyt from your wasm).

cheers,
sam





Ideas anyone?


Thanks, Phil.




--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/emscripten-discuss/1782500011745%40dmwebmail.dmwebmail.chezphil.org.

Phil Endecott

unread,
Jun 27, 2026, 9:59:21 AM (5 days ago) Jun 27
to emscripte...@googlegroups.com
Hi Sam, thanks for your reply.

'Sam Clegg' via emscripten-discuss wrote:
> On Fri, Jun 26, 2026 at 11:53⬯AM 'Phil Endecott' via emscripten-discuss <
> emscripte...@googlegroups.com> wrote:
>
>> Dear Experts,
>>
>> I compile my source files to .o object files and then link with
>> something like:
>>
>> emcc -O3 --preload-file foo.dat --shell-file shell.html abc.o def.o
>> ghi.o -o out.html
>>
>> If I've only changed shell.html or foo.dat, can I avoid re-linking?
>> Since there is a lot of link-time optimisation going on, linking is
>> slow. I'd like to avoid that when it's not needed.
>>
>> I'm wondering if there is some way to link the object files and do
>> the link-time optimisation, and then in a further step add the
>> preload files and shell.html to make the final outputs.
>>
>>

> I would recommend against using `--shell-file` unless ou
> have a really good reason too. Its normally easier to have emcc project a
> `.js` file and then have a fixes `.html` file checked in for you app.
>
> Likewise, do you really need to use `--preload-file`? In most cases I
> recommend using `--embed-file` (unless you really want to deploy your data
> separelyt from your wasm).

I started with the tutorial at https://emscripten.org/docs/getting_started/Tutorial.html
which uses "-o hello.html" and "--preload-file".

Is there a basic example somewhere of using a fixed .html file? I.e.
what does the HTML need to do to load the .js, and how should emcc
be invoked to generate the required .js?


> I did add an option called `--post-link` which could be just what you want
> here. It lets you pass an already-linked wasm file to `emcc` instead of
> object files. So you would run your build once as above and then for
> followup builds you could pass the `--post-link foo.wasm` instead of the
> object files. This a lesser used option though, so you could run into
> issues with it.

Thanks, I'll look at that too.


Regards, Phil.







Leo Schubert

unread,
Jun 27, 2026, 10:57:52 AM (5 days ago) Jun 27
to emscripte...@googlegroups.com
Hi Phil,
the html file just needs to have a script tag like this:
<head>
..
<script src="main.js"></script>
...
</head>
<body>
Hello world
</body>
</html>

and you call emcc with
$ emcc main.c -o main.js

main.js contains the JS code to load the main.wasm, so it doesn't need an explicit mention in the command line.

See this little GitHub project https://github.com/leopatras/em_hello_asyncify which demonstrates also how to interact from C with JS and vice versa using the ASYNCIFY feature.
(see https://emscripten.org/docs/porting/asyncify.html)
HTH, Leo
> --
> You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/emscripten-discuss/1782568754382%40dmwebmail.dmwebmail.chezphil.org.


Phil Endecott

unread,
Jun 27, 2026, 12:50:31 PM (5 days ago) Jun 27
to emscripte...@googlegroups.com
Hi Leo,

'Leo Schubert' via emscripten-discuss wrote:
> the html file just needs to have a script tag like this:
> <head>
> ..
> <script src="main.js"></script>
> ...
> </head>
> <body>
> Hello world
> </body>
> </html>

Thanks... I was under the impression that the {{{ SCRIPT }}}
in the shell.html must be doing something more complicated
but actually it just inserts <script async src="example.js">.


Regards, Phil.




Sam Clegg

unread,
Jun 28, 2026, 8:19:57 PM (4 days ago) Jun 28
to emscripte...@googlegroups.com
I believe that historically the {{{ SCRIPT }}} template may have done more than it does today, and it does more in certain modes like `-sSINGLE_FILE`, but in general is beasically jsut doing  `<script src="main.js"></script>` yes




Regards, Phil.




--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages