DEV Community

Cover image for Remove Angular SSR code when serving to the client
Kerschbaumer Stefan
Kerschbaumer Stefan

Posted on

Remove Angular SSR code when serving to the client

Did you ever notice that when you are using Angular SSR the server side code also gets served to the client?

To prevent that i made a small library called ngx-ssr-code-remover which removes SSR code post building by analysing the bundle files.

As you can see, without using my library the code served will contain my "secrets".

Image description

After adding two lines of code on the server side, and a decorator within the component everything gets removed.

Image description

Currently this lib is only tested with angular 18.1 using esbuild.
Also i didn't change any production build configs.
Lazy loading works fine and supporting providers is planned in the feature.
Feel free to checkout my repo, and/or give me feedback.

https://github.com/xsip/ngx-ssr-code-remover

Enjoy your day and happy coding!

Top comments (1)

Collapse
 
vkinsane profile image
Vishal Khandate

Interesting approach! Removing Angular SSR code when serving to the client helps optimize performance. Thanks for the detailed explanation