DEV Community

Yogesh Galav
Yogesh Galav

Posted on

Why I fed up with Inertia?

In recent times while working as Tech lead, I was very much obssesed with optimizing loading time of website and our product website literally took 10-15 secs to load.
That's a good reason of frustration right?
Our Team had done many efforts to resolve the same but all in wain.
We purchased CDN, optimized queries, defer loaded resources, but nothing decreased that FCP time. BTW each optimization has it's own benifit and other then FCP they really bring calculative changes.

But from user perspective we have done nothing for months😔

Hence it was the time to remove the culprit we always avoided, because it was love of otwell and people always defended it including me😅
You guessed it right, the culprit was inertia itself. and it's drawback which can never be cured is server call before every page load.

Suppose I'm sitting in India and server is located in USA, then here's what will happen.

  1. First the DNS will resolve then our server code from usa will run and return html result to India.
  2. After loading Html your browser will know, Ohh! it uses Inertia I need to again request to server if I can open this route or is there any prop I need to load before loading and executing anything else.
  3. Then our holy grail inertia request goes to USA and fetch little props and check conditions which most of the time is not present on get routes.
  4. After this long awaited time in which we can do nothing, Now our browser in India will start loading css,js files mentioned in html from USA or CDN.
  5. Now the time comes when our js will execute and render the page to user.

You can understand better if you use inertia and look in network tab.

Inertia lovers will suggest solutions to problems generated by inertia itself but I will argue with them one by one.

  1. First as I mention all the solutions are to coverup drawbacks of inertia which were never present in first place.
  2. From Inertia 2 there are solution like load resources on hover of link or load before user's intention. It will always work if you have rich pocket, but what if server is already busy with loading resources and pages of 100 other users at the same time and with php you know the condition, right?
  3. If you use api's only atleast you can load and execute frontend and show loaders.
  4. If you want to save effort of writing routes 2 times, with packages like uplugin-vue, you wouldn't have to write your url even once and at the same time you can maintain folder structure for frontend with file based routing.
  5. Last but not the least, if you need roles and permission on every route, or need some initial data as alternative to HandleInertia, You can do that via window variable.

Every technology has it's own pros and cons but I think every B2C product has heavy traffic or busy server and want to save costs, hence take your decisions accordingly. A single inertia request before page load wouldn't cost you but thousands and millions will.

I hope you enjoyed reading this,
Thanks and have a nice day.

Top comments (0)