Mostafa001's avatar

Is Mixing SSR and CSR on the Same Page a Good Practice?

Hello,

I'm working on an eCommerce project for learning purposes using Laravel. I want to know if it's okay to use both Blade templates and API endpoints within the same project and even on the same page.

For example, I have a product page that I plan to build using a Blade template. However, I also want to include an area on this page where I can make JavaScript AJAX calls, such as for an "add to cart" feature. Is it acceptable to combine server-side rendering (SSR) and client-side rendering (CSR) in the same project and page?

Thank you!

0 likes
2 replies
experimentor's avatar

@mostafa001 I believe there is nothing stopping you from implementing ajax calls from a blade file. If it works securely and makes for great user experience, it is good and very much acceptable... no matter what some purists may say.

Having said that, please explore Laravel-Livewire. It is very powerful and could give you exactly what you are looking for.

1 like
Lumethys's avatar

if you were doing this in a JS framework, they will call it "Island Architecture"

i'd wager 99% of app that are not using a frontend framework such as React, Vue,... are doing that.

However, it is quite an outdated pattern as of now, since it is pretty hard to manage. Nowadays, eitehr people go with full-blown JS frontend, or use some sort of framework-specific SPA-like engines.

For Laravel, we have Livewire and Inertia.

For Rails, they have hotwire.

For Spring, they have Vaadin.

For C#/.net, they have Blazor.

1 like

Please or to participate in this conversation.