Slimmer sgcWebSockets Builds — Exclude the Embedded JS Resource

· Features

A long-standing question from customers profiling their executables is «why did my EXE grow after adding sgcWebSockets?». Part of that growth comes from a resource file that the sgcWebSockets runtime packages embed by default: sgcResources.RES. It contains the JavaScript client bundle that an sgcWebSockets server can deliver over HTTP to a remote browser — a feature most Delphi and C++Builder applications never use.

Starting with sgcWebSockets 2026.6, you can opt out. The source-edition Setup gains a new Include Resources checkbox on the Options page; unchecking it undefines a new SGC_RESOURCES compiler directive in sgcVer.inc before the runtime packages are compiled. The resource is simply never linked in — not into the BPLs, not into your customers' EXEs.

What gets removed

The {$R} directive in the sgcWebSockets source is now wrapped in {$IFDEF SGC_RESOURCES}:

// sgcWebSocket_Protocol_Base_Server.pas
{$IFDEF SGC_RESOURCES}
{$R sgcResources.RES}      // sgcWebSockets JS client bundle
{$ENDIF}

When SGC_RESOURCES is undefined, the linker has nothing to embed. The resource simply disappears from every executable that links against the source.

When you don't need this resource

The embedded bundle is only needed when an sgcWebSockets server actually delivers the bundled JS client to a remote browser. That happens with TsgcWSProtocol_JS_* components, or any server that responds to GET /sgcwebsockets.js by returning the bundled JavaScript.

It is not needed for:

How to enable it

The cleanest path is the installer. When you run the sgcWebSockets source-edition setup, press the Options button and uncheck the new entry:

[ ] Include Resources

The installer will rewrite the {$DEFINE SGC_RESOURCES} line in sgcVer.inc to {.$DEFINE SGC_RESOURCES} before compiling any package, so the design-time and runtime BPLs are produced without the embedded bundle.

If you already have sgcWebSockets installed and prefer to make the change manually, open <sgc-install-folder>\Source\sgcVer.inc, find the line:

{$DEFINE SGC_RESOURCES} { RESOURCES }

and comment out the brace:

{.$DEFINE SGC_RESOURCES} { RESOURCES }

Then rebuild the runtime / design-time packages and your application. Visit Project > Build All Projects in the IDE, or run your usual build script.

Measuring the saving

If you want to confirm the saving on your own project, generate a detailed linker map before and after the change. After rebuilding, open the generated *.map file and scroll to the resource section — sgcResources.RES should be gone. The .text module size for sgcWebSocket_Protocol_Base_Server drops slightly too, because the helper code that loads the resource is dead-code-eliminated.

The exact saving depends on your build configuration and which sgcWebSockets edition you use, but on a typical client-only build the EXE shrinks noticeably. If you combine this option with the existing edition-level switches ({$UNDEF SGC_EDT_ENT} to drop WebAuthn / HTTP2 / OAuth-server, or removing uses sgcWebSocket in favour of uses sgcWebSocket_Client in client-only code), the total reduction can be substantial.

Backward compatibility

The default in sgcVer.inc remains {$DEFINE SGC_RESOURCES}, so existing projects continue to compile and run exactly as before. The new flag is strictly opt-out: nothing changes unless you explicitly disable the resource, either through the installer checkbox or by editing sgcVer.inc yourself.

If you disable SGC_RESOURCES and then call a server method that tries to serve the bundled JS client (for example, a TsgcWSProtocol_JS_* response handler), you'll get a clean EResNotFound — an obvious signal that you turned off something you actually needed. Just re-enable the define and rebuild.

Availability

The new option ships in sgcWebSockets 2026.6, in the source-edition installers only (Standard, Professional and Enterprise). The Trial installer keeps the resource embedded so the bundled JS client demos work out of the box.

Customers with an active subscription can grab the new build from the customer area. Questions or suggestions for further size-reduction switches? Get in touch — you will get a reply from the people who wrote the code.