Build Full-stack Product series: What I Did Wrong

Lương Như Toàn
4 min readDec 20, 2018

--

Learn from my mistakes while building full-stack products (Javascript-based Fullstack: #ReactJS #NodeJS #Meteor #MySql #ReactivePrograming)

Why did I decide to write this article

Sharing my mistakes + I don’t want to make these similar mistakes again

1. Wasting loading resources and wasting rendering

Wasting loading resources and wasting rendering slow down and create negative impact on your product. So only preload resources always being used or regularly being used.

What I want to implement: I want to show a list of short movies that related to current playing movies When user pause at the end of the video && that video type is movie && the video is playing in full-screen mode.

It’s rarely being showed so I should not preload <ShortMovies /> all the time

<ShortMovies /> is shown at Full-screen mode at the end

Bad:

Even when visibility = hidden. All image resources still being loaded and <ShortMovies /> is still being rendered

ShortMovies is a component showing list of movies

wasting loading resources and render while it’s not being shown

Good:

Solution 1: use display instead of visibility.

Notice that when using display, <ShortMovies /> is still being rendered no matter display = none or not. The different between display & visibility is when display = none, all image resources are not being loaded through network while all image resources always will be loaded with visibility. You can check it out by inspecting from DOM.

Notes: <ShortMovies /> is still being rendered when display = none

Solution 2: only render <ShortMovies /> when needed.

<ShortMovies /> will not be rendered and all image resources will not be loaded when willShow = true.

only render <ShortMovies /> when needed

2. Forget to add meta tags for the website

Here is my example of adding meta description tags for SEO:

E.g of adding meta tags for my website: https://luongnhutoan.com

Adding meta tags help all website’s content appear on google look like this:

https://www.google.com/search?q=luongnhutoan
https://www.google.com/search?q=luongnhutoan

For more information about adding meta tags:

3. Store and read hide data on DOM instead of reading from the React’s state (Model)

If you use React, you should not read/store hide data on DOM

If you use React, you should not read/store data on DOM. When elements have disappeared or haven’t rendered yet or un-existed and many unknown cases… In those cases, the results from reading data on DOM would be null => Oops Mr.Bug begin here! That’s why instead of reading data from DOM you should read it from a model. In most cases, you just need to read data from React’s state or Redux’s store…

Remember, React is designed to do all those jobs interacting with DOM for you. You should not do it.

Thank you for reading. I hope you guys learned something from my mistakes and having a fantastic day. DIY — Do not repeat yourself to make the same mistakes. I will keep updating this article so stay tuned!

Follow me on my blog:

--

--

Lương Như Toàn

Hungry Solopreneur, Software Engineer passionate about turning ideas into real products. Hey YOLO! (You only live Once). My Blog: https://luongnhutoan.com