
Curious software engineer
Search for a command to run...

Curious software engineer
No comments yet. Be the first to comment.
In this series, I will treat subjects related to software development, software engineering, and related career.
One annoying thing that is not supported in Workflows yet is date. What a pity, to not have a date picker available in your workflow. And even a variable that be the date time of when a form has been submitted. Fortunately, it is not hopeless. By c...
It’s the summer holidays, after all. So I wanted to spent some time with my 7 years old daughter to teach her programming. ⌨️ I spent some time before discussing with her some of the basics concept verbally: the different parts of a computer, and bas...

This article is a follow up on my previous one introducing the concept of SE Spectrum: https://sonny.alvesdi.as/a-better-way-to-discuss Existing solutions For long, the easiest way to run a spectrum was to use visual drawing or diagram tools like ...

Introduction to SE Spectrum

One of the greatest tool available on GitHub is Dependabot. For those not familiar with it, in short it's a bot reviewing your list of dependencies and proposing PRs to update them. https://docs.github.com/en/code-security/getting-started/dependabot-...

Photo by Harli Marten on Unsplash As long as I remember I have always been interested by skepticism. And I think one element that really resonated with me has been that conference talk by Phil Plait: https://www.youtube.com/watch?v=FrFRbGjUtJk 15 ...

The concept of SSR can be confusing. It was especially for me, coming originally from PHP world where everything (or almost) is rendered by the server.
Here is a list of reasons:
Did I say SEO 3 times? Well yes, it is important. Crawling bots won't load your JavaScript angular app. So if your meta tags and microdata content is not there in your HTML content, they will never know about it.
It also increases accessibility to your website, as browsing without JavaScript is made possible. But then increasing accessibility is also going to increase your SEO!
ng add @nguniversal/express-engine
That's it...
This is where it becomes different from a client side build. With a client side build you can serve it very easily through a web server like Apache or NGINX.
With SSR, you need NodeJS.
First, you need to build:
npm run build:ssr
Then to run your app:
node dist/server/main.js
Note: Assuming your server build is located in dist/server/main.js
If you carefully look into the dist folder, you will see your server build for SSR, and also the client build like before.
For SSR, you need both.
And below, the chart illustrates how it works when browsing your website.
In shorts, the server build will call your client build from its parent folder to render your app. Once it rendered the page, it will send back the HTML with its content prerendered.
During the time that the client build actually loads up in the client browser, it will continue to display the prerendered content. But as soon as the client is ready on your side, the prerender content is flushed and the client logic is triggered.
As long as we don't refresh the page we will continue using the client, the endpoint in the address bar will change each time we click on a link, but actually those don't trigger page loading. The Angular client intercepts the event and does its magic to only update what needs to be updated on your current window/document.
But if you do a refresh, then it will call again your distant server with SSR and repeat the process to prerender pages.
No it's not.
This is the cool part, which makes your server not too busy and your website browsing faster since everything needed is loaded up in your browser.
Well, mostly two things:
In order to optimize the render time on server-side, you can use isPlatformBrowser or isPlatformServer in a condition to only request the essential data in your page. And by essential, I mean, anything important for your SEO.
To avoid the flushing to be visible to your visitor, you want your client to quickly get the content on his side too. So you should definitely avoid to big content. Use pagination, use a CDN, and optimize your data.
https://angular.io/guide/universal
https://angular.io/api/platform-browser/TransferState
Photo by Christina @ wocintechchat.com on Unsplash