Asp.Net MVC: Serverside or Clientside Parsing HTML Content - javascript

What are the pros and cons of processing/creating/parsing HTML server- or clientside.
First Process:
Parsing the html-data on the serverside via Razor
Passing this HTML-code the clientside and include this
Second Process:
Passing data to the clientside
Parsing these for example with javascript for producing HTML-code
Currently, I find only Cons for the first one
The chunk of data is larger, because we are sending not only the
data to the client
Parsing the data on the serverside costs more
for the company.

For the Second Process: The data and all its processes (business logic or sensitive data) will be available for the client to see.
Also, rendering time of the page will depend on the client's computer since its executed locally and not in the server.
My suggestions would be to stay server side to protect your data processing.

Seems like this is mvc vs angular. The difference for me is the indexing of pages by google and other web crawlers. If that is not a concern I like to do as much as I can in the client, and angular or other such html frameworks provide the 'parsing' functionality, as well as two way binding, services, and a host of other features that make client side development in HTML a breeze.

Related

NodeJs Rendering HTML Template + Logic at server side

Hi I am developing a widget module in my existing Angular 1 based UI project. This widget is supposed to contain real time information.
As per my design, I want to send html view to client from node server(maybe using express js) when the first request is made. But as the data needs to be real time, I cant afford to send the complete html every minute(will be duplicate template transfer each time).
So is it possible that I send a template to client along with a set of java-script functions so that when ever client wants that data to be refreshed, he will just invoke the sent javascript function and internally my javascript function will make a rest call, get the json response from server and again repopulate the html sent initially.
This way I am planning to have initial rendering at server side and subsequent rendering at client using the logic provided by server. Here client will not be aware of which widget it is rendering and what functionalities it has. All those will be controlled by js sent from server.
Please do let me know how to achieve this as I find ejs not serving this purpose. With ejs, I need to have all logic to server side only. Whereas I plan to transfer logic from server to client at run time.
Also if my design is having some serious problems, do suggest some other alternatives. Thanks
Angular1 is not server side rendering friendly as it needs browser DOM. Use of any templating engines wouldnt help either as the html generated by them are not picked up by the angular app.
Use a phantomjs headless browser instance to generate html by running ur angular1 app code and then angular will run in client side when scripts have loaded.
I would recommend switching to Angular2 or React as they are server side rendering friendly

how to store json file at server using asp.net as server side language and how to access json data using javascript, html and css?

I am a newbie in web development. I am in the process of building a food blog website. I want to pursue front-end-web-developer career. I have built my website only using client side languages like javascript, jquery, html and css. I have used json to store the data. my questions are -
1. I now want to make my website live. For that I want my website to be hosted on server. As I am not using any server side scripting, would my data related to website be visible to everyone if they do try to "inspect element" or "view source"?
2. how can I separate Json from client side code/scripting? I think for that I will have to seperate json data from other javascript code and store it into a separate file on a server. But in that case how can I access the Json data? For that I will have to make use of some server side scripting language. I prefer Asp.net(not that I know asp.net but I am familiar with C# hence). I also would have to make changes to my html code at client side to fetch the Json data from server. I am not really aware of this whole thing. Could someone spare some time and let me know how to go about it?
3. Does all the client side and server side code lies in a single asp.net project?
I have searched over internet. Mostly all the material/coding available over internet is mostly in php or python hence I am confused. There no definite guideline that I could find as how to handle the data part only using JSON?
to help you answer your 2nd question
2. how can I separate Json from client side code/scripting?
usually server side is in the controller so your HomeController.cs for instance will have an Index action (public ActionResult Index()) that method will basically be called whenever the browser hits the route Home/Index.cshtml
in order to separate these two, you may fetch or construct your Json in the controller and pass it to the ViewBag, from there you can access it in the view.
using $.ajax will help as well to get the json from the view and update the content of a specific part of your page for instance.

Hiding Parse javascript SDK files and blocking client from running js

I'm working on a Parse web app and have run into some problems using the backbone.js based client side javascript sdk. I noticed the way I have things set up, the client can view all of my source code by simply using the dev tools to view source files and can also run code against the database (within the limits of the ACL's I've set). I've started working on rebuilding the app in cloud code using the Express.js module Parse provides so that all of my code is stored server side, but I was wondering how those using client side frameworks get around this obvious problem.
That's the issue with client-side code. Assume any code you send to the client is hacked, broken, and tampered with.
With JavaScript, your best bet is to use either Cloud Code and send AJAX or streaming data calls to the server, retrieve the data from the server at runtime (not super secure, but would fool some people), or accept that your code is vulnerable.
I typically work with frameworks in the MVC format, so I only expose a limited subset of the actual model via a REST API. I use both a client-side framework and a server-side framework. Any thing sensitive goes on the server.

Json data formatting best practice

I have a SPA web page. Data are loaded with ajax requests. I need to show some culture sensitive data on that page. What is the best way for formating this kind of data?
Basicaly I have two options:
1. Send all data preformated to client (preformat on server)
Preformated
{
DurrationInMinutes = '2 min'
DurationInSeconds = '120 sec'
}
Pros:
Easy server side implementation (Asp.net mvc back-end).
Everything is in one place (one method in BLL).
Smaller JavaScript
Cons:
Posible data duplication (same duration data shown in minutes,
seconds i.e. diferent format but same data).
2. Send raw data to client (format on client)
RawData
{
Durration = 1645678 // milliseconds
}
Pros:
Easier unit testing (we can test everything in c#)
Easier maintenance - our developers are more expirienced in c# then
Javascript
Cons:
More work has to be done on the client side
I'm not sure if all data formating can be easilly done in javascript
Edit
I end up with client side option
Thanks
For just simple presentation of the data, both methods are OK. But keep in mind a couple of other considerations:
All data sent to the client is in principle available for the user, even if it's not shown directly. This can in some situations be a security issue.
Sending the raw data to the client and letting the client handle the rest gives more possibilities for dynamic viewing on the client side
Depending on type of application and data, sending data to the client can reduce load on server. However users with slow clients can be an issue.
If none of these considerations apply, I would go with what is most optimal for developing and maintenance. The answer then depends on local issues, resources, framework used etc.
I don't understand the cons of the server side option - how is is that formatting things once will cause that? Specially when you can keep your localized data in resource files, and simply let the framework handle the localization with a simple configuration? And yes, AFAIK, pure Javascript doesn't have all the same localization capabilities of .NET (or Java, or any other framework, for that matter).
Also, the pros of the client side option - How is it that coding in the side your dev are less experienced helps unit testing and maintenance? Do you think that just because it's not on server side, it doesn't have to be tested to be ok?
My two cents: unless you find a Javascript framework that can do that, let the server side handle it. Otherwise you'll be reinventing the wheel. Also take into account that the more logic you have on the client side, the worse your site look-and-feel will be on low end machines, tablets and cell phones.

How to combine JMVC (javascript-mvc) and server side MVC together

I have asked this quesion few days before here and no one answered it.
I had asked it in forum.javascriptMVC.com too and now I have a answer, however I need a a bit more idea.
Question:
I read javascriptMVC's documents and I loved it.
But I don't know how to use it in a large scale project.
I think on the server-side a MVC framework is needed or can help so much. And I've worked with server side PHP frameworks.
I am confused, my understanding of JavascriptMVC projects is that they handle client side events on the browser capture events, execute AJAX requests, manage the responses/data from the server and also show them to user in a graphical interface.
I know that in PHP MVC projects we also have controllers (and actions) that any of them is a separate page with a single entry point, my point is that these pages are whole HTTP requests.
I think the combination of these two frameworks would be in a form of a single or few heavy files (including js , css , imgs etc) that loads and managed by another Javascript libary such as steal.js.
Now user can work with site and its actions (as events) that result in running js functions that may change something in the UI or cause a AJAX request, as in Yahoo Mail where most things happens in one page.
So how will this affect the design of controllers and actions in PHP ? I mean normally in PHP MVC frameworks a lot of controllers and actions means a lot of pages. I think because of AJAX the number of controllers and actions should be actually less. I also think because of JMVC most controllers (and actions) should turn to AJAX responders, however how are layouts and views to be handled in this context?
Finally
I want to know about different aspects of using this method(JMVC+MVC). (I am using Yii as my server-side MVC framework and JavascriptMVC as my client-side MVC).
I also want to know about management of data on the client-side.
I would like to understand how AJAX and web-sockets could be used, where we can use AJAX and where we can use websockets?.
I want to understand about local-storage how we can use it for simulated page data management and maybe caching, how we can cache data coming from server as JSON in a form of a page? I am working on a very large project and I want to build its foundation very strong.
Say that you jave a JMVC framework where
The model gets data from the server using AJAX request - expecting JSON results.
The view does not rely on the server, for more that providing the raw HTML.
The Controllers do not rely on the server, for more that serving the JS files.
Essentially you use the server what it "should" be used for, data storage and processing, while you let your client browser handle all the tedious stuff.
Now, lets see how to define a server-side framework. As I see it we have several options, all of them fairly similar, albeit somewhat different (all returning someing in JSON format):
A fully fledged MVC such as cakePHP
Custom implementation
WebService implementation
Personally I would use a WebService, and I already have. Or rather, I used a WebSocket based JSON-RPC WebService.
Using a fully fledged MVC will have it's drawbacks in maintainability and, not insignificantly, server load. But it is very possible, just implement a view which formats the page as JSON...
Making a JMVC client does not, in my view, mean that it cannot request new HTML from the server. But it does mean that that requested HTML should be free of data, other than meta-data the Java-View needs to know where to put data recieved from, for example, the WebService.
So a main page in the JMVC could just contain a single
<div id=content></div>
and menu clicks can fetch a subpage from the server and load the content into content. Then that loaded content can contain some more javascript which starts WebService requests to get data from the server, to display in the empty placefolders it in turn contains.
First check https://stackoverflow.com/a/4458566/718224 after that you can move forward.
Try this (from https://stackoverflow.com/a/8424768/718224)
No, you don't need to use it server-side, but it will help with organization / separation of application and business logic. Depending on the scale of your application, that could help tremendously in the future.
The key is just making sure you organize your backend code well, otherwise you will end up with a monolithic and/or difficult-to-maintain codebase.
Server-side views would contain your HTML and any JavaScript that may or may not make requests to the server. This assumes that you are actually using PHP to build the pages that a user navigates to.
If you have a static html page that builds itself using AJAX requests, then you may not need to use server-side views at all. Your controllers would more than likely be outputting JSON data. If this is the case, it doesn't make models and controllers any less useful.
Try this (from https://stackoverflow.com/a/8424760/718224)
If you are using any of the major PHP frameworks (CakePHP, Code Igniter, Symfony, etc.) then you ARE using MVC already. If your server side logic is more complex than just a few really simple scripts than you probably should be using one of those frameworks listed, using MVC on the server and the client.
Many (most?) larger web apps being built today are moving towards using an MVC framework for both client-side and server-side application code. It's a fantastic pattern for separating concerns for many large applications, especially request/response server apps and event-driven browser apps.
Try this (from https://stackoverflow.com/a/8427063/718224)
Backbone.js connects your application over a RESTful JSON interface. I honestly find that it works wonderfully in conjunction with the MVC framework. If you build a RESTful API, you can let you server manage CRUD updates quite easily. All your server side code will be responsible is saving and sending back JSON objects to Backbone.js. Then let most of your logic and magic happen within the Backbone.js framework.
Try this (from https://stackoverflow.com/a/8078282/718224)
First, a client-side MVC framework like Backbone isn't just for single-paged apps. You can also use it to add some rich interaction to one or many views of a more traditional app. They simply provide structure and data abstractions on the client.
Next, these client-side frameworks are designed specifically to work with your back-end MVC frameworks. Backbone.js (since you tagged it specifically) models and collections work with REST services. They will talk via GET/POST/PUT/DELETE verbs and will ultimately communicate with your controllers on the back-end when they make asynchronous requests.
In the case of Backbone, it talks JSON instead of HTML. In the case of Rails, this is really easily handled in the controller. If the request is an HTML one, then you return a view as HTML. If it is a JSON request (*.json or Content-type) then the controller returns a JSON representation of the data. I am assuming that it is as easy in Django as it is in Rails to have the same controller respond to multiple content requests (HTML, XML, JSON, etc)
may this help you.
client side web apps and rich client side web pages often use jmvc backbones and etc. and with that kind if js libraries and HTML5 technologies like webstorage you can have a more applocation like websites that all things happens in client side like templating management and etc. and just we have ajax request/response to servers to get/set data or update status. and abput first section they are right a jmvc site are more like a single pages websites. ie hotmail yahoo , etc.

Categories

Resources