javascript - Difference between WebApp that connects to API vs backend rendering -


sometimes when create basic web tools, start nodejs backend, typically creating api server expressjs. when routes hit, server responds rendering html ejs using live state of connection , sends on browser.

this app typically expose directory public static resources , serve well. imagine creates lot of overhead form of web app, i'm not sure.


other times start api (which exact same nodejs structure, no html rendering, state management , api exposure) , build angular2 or other html web page connect api, load in information on load, , populate data in page.

these pages tend rely on lot of ajax calls , jquery in order refresh angular components after bunch of async callbacks triggered. in structure, i'll use web server apache serve files , define routes, , js in web pages rest.


what overall strengths , weaknesses of both? , why should use 1 strategy versus other? both viable , dependent upon scale , use? imagine horizontal scaling load balancers work in both situations.

there no or bad approach choose. each of approaches described above have advantages , need decide 1 suits best project.

some points might consider:

server-side processing

  • security - dont have expose sensitive information (api tokens, logins etc).

  • more control - have more control on resources

  • "better" client support - clients (ie) not support same things others. rendering html on server rather manipulating on client give more support clients.

  • it can simpler pre-render resources on server rather dealing asynchronous approach on client.

  • seo, social sharing etc. - how server sends resources, thats how bots see them. if pre-render on server bot able scrape site, tag etc. if on client, see non-processed page. being said, there ways work around that.

client-side processing

  • waiting times. doing stuff on client-side improve load times. careful not many things since js single-threaded , heavy stuff block ui.

  • cdn - can serve static resources (html, css, js etc) cdn faster serving them server app directly

  • testing - easy mock backend server when testing ui.

  • client front-end particular application/device etc. more logic put client, more code have replicate across different clients. therefore if plan have mobile app, better have collection of apis call rather including logic in client.

  • security - whatever runs on client can read client. no matter how minify, compress, encrypt resourceful person able whatever wants code

i did not mark pro/con on each point on purpose because decide is.

this list go on , on, didn't want think more points because subjective, , in end depends on developer , application.

i tend choose "client making ajax requests" approach or blend of both - pre-render on server , client takes care of rest. careful latter though break automated tests, ide integration etc. if not implemented correctly.

last note - should always crucial validations on server. never rely on data client.


Comments