I want to use markdown in a website, I'm wondering about convert markdown to HTML client side or server side. I'll use https://github.com/evilstreak/markdown-js that has both client/server libraries. (node.js)
I never used markdown before and I'm wondering about the efficience of the two ways, the security too, because I don't want to have html tags from users (injections)
Do you have any advice or explanation about why do it client side or server side? Thanks.
If you're looking for efficiency, you should use the same module to render at both server-side and client-side.
Server side rendering is needed for initial request, and if your data is updated somehow by user, it needs to be re-rendered at the client-side.
Reasons:
client-side rendering is too slow for initial request because user needs to fetch all libraries first
server-side rendering is too slow for using after the page is loaded because it needs additional requests
Related
I am kind of in cross roads in the process of understanding the basic difference between Client Side Rendering and Server Side Rendering. After doing significant amount of research, here is my understanding
When we render on to the server it means:
You have a local server say Apache Tomcat, You host a web application
by clicking the run on server, It renders your HTML on the server.
I understand this completely. Now here starts my confusion:
Client Side Rendering?????
You host a web application without a local server???
I might be wrong, but this is what the conclusion it is taking me too.
I know, ReactJS does both serverSide Rendering and Client Side Rendering. However, I am not getting the basic difference between both these renderings.
Any help would be highly appreciated.
"Rendering" in this context means "Assembling the document from various component parts".
With server side rendering, you would do all that on the server and then send a complete HTML document to the browser.
This is:
Traditional
Robust
Search engine friendly
With client side rendering you would use client side JavaScript to load a template and some data (using multiple requests) and then put them together in the browser to form a DOM and create a page.
This can provide performance benefits for subsequent pages (since less data is being fetched for them) although the cost of bootstrapping the initial page is usually higher.
Lack of robustness and search engine friendliness can be compensated for by combining the techniques. A new request for a page (any page) uses server side rendering, but following links trigger JavaScript to involve Ajax, the History API, and client side rendering. If you use server side JavaScript, you can reuse some of the same code for both (this is sometimes called Isomorphic JS).
I am getting data on the client side via websockets and laying it out via js. I want to add button to create pdf (using SelectPDF C#.NET). The data for the pdf is the same as on the page, yet the layout is completely different. I would like to send the data to the server side (e.g ajax with my data structure) and create layout on the server side, render it and then pass to server side SelectPDF for pdf creation.
1) Is it possible to send data from client side to ReactJS.NET to create the layout on the server side?
2) If not ReactJS, what would you recommend to use for server side rendering and then sending the rendered file to SelectPDF?
Thank you
If you want to render react content from your server, you have to be sure your production enviroment has internet access (not recommended) to take cdn reference to Reactjs libraries or keep that libraries local.
High level diagram
Is there a way to send data from a client to the server using only JS and then fill out a form on the server and then the client gets redirected to the server and see a prefilled form?
I'm thinking using ajax sending a json object. But I'm not sure that will work.
I believe you misunderstand the concepts of server and client. The client is the computer you are using, the server is the computer where the website service runs.
PHP is your server-side code, which runs on the remote computer which serves the requests of the user computers.
Javasceipt is your client-side code, which runs on the computer of the users.
You need to create the HTML structure of your form as part of the HTML which is generated on your server. In your HTML structure you can have some small PHP scripts where you "inject" programmatically calculated values. Read more here.
In general, if you create a form, you not necessarily need AJAX (Asynchronous Javascript And XML). However, for advanced handling of your forms you might need to use AJAX. There are a lot of references, just use your search engines and view a few tutorials.
Suppose I have server. A client loading an HTML file containing a javascript library will have the script executed by the browser. The problem here is that if the client's computer is slow, the processing will take a long time.
So I want to move the processing to the server side. But, instead of having to rewrite the entire javascript library into another language, I simply want to run the javascript on the server.
Googling "server side javascript" directs me to Node.JS, which in my imagination have the capability to do so. But, I cannot find a tutorial which does just that. Does this mean that there really is no easy way to do so? For example, because the javascript script may contain DOM specific things such as document.getElementById(), which does not make much sense on the server side.
There is no trivial way to simply shift processing of JS from the client to the server.
You need to break the code down into code that must run on the browser (such as, assuming you don't want the browser to load an entirely new page, DOM manipulation) and code that can run on the server.
Then you need to provide a way to pass data between the server and the browser, this is normally done via HTTP (using Ajax).
When you take input from the client you need to send it to the server in an HTTP request (instead of just passing it as an argument to a function). The server needs to read the HTTP request, process it, and make an HTTP response.
The Ajax callback then needs to parse the response and run any client side logic (such as DOM updates) in response.
Note that network communication times will impact performance.
You can't "merge" the client and server in this way. All you could do is process the data on the server and just display it in the client without any further processing. Maybe you should refresh you knowledge about HTTP and how websites are send to the clients. Without any additional tricks, like websockets, comet or ajax polling, you can't access the client after you send the initial website to it. Even than you can just send data to the client.
When you want to stick to Javascript, Node.js is a good option. But even than you would need to send the data you want processed to the server, process it there and send back the processed data in JSON or "display ready" HTML.
I am trying to use ajax to generate pages on the client side, and so far I got two ideas of doing it:
I can load a page with basic DOMs, JS and CSS files from server, then I can make an ajax call to get data from the server and generate pages on the client side.
I can load a completed page with JS and CSS files from server, and I can make an ajax call whenever users want to update the contents.
I don't like either of the two methods (both of them will have page templates in JS code). The first one is making extra an request to the server; the second one requires me to make another 'copy' of template in the php code.
Is there any suggestion to make the structure cleaner?
UPDATE:
I feel maybe it's good to generate the whole page at the server side when the page is not too big (i consider a table with hundreds of rows is big and it cost a lot for server to generate all those html tags around the data), and in this case, you just need to use ajax to pull the page instead of getting json data from the server then generate the page.
From my experience, there are two scenarios in which you'd want to render client-side:
You are building a pure client-side JS application.
You want to serve the data for different platforms (web, desktop, mobile native).
Unless you identify your page with one of the previous scenarios (which I assume you don't), I recommend you to render in server side. Although the response is going to be bigger (server side computing time is negligible), the perceived speed compared to client side rendering is going to be faster.
If you need to serve a very big page, note that you could autoload chunks of HTML via AJAX whenever the user reaches the bottom of the page without the need of client side templates.