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!

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

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

Cloudinary image

Zoom pan, gen fill, restore, overlay, upscale, crop, resize...

Chain advanced transformations through a set of image and video APIs while optimizing assets by 90%.

Explore

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay