JDK8 + Facebook React: Rendering single page apps on the server
augustl.com
augustl.com
You can put initialization code that needs to be done both in client and server in componentWillMount. Code that needs to be executed only in the client (ex jQuery integration) should be in componentDidMount which is only executed in the client.
I'll make sure it is documented. Edit: https://github.com/facebook/react/pull/1288/files
Is there a tutorial targetting such scenario specifically?
1 - https://groups.google.com/d/msg/scala-js/DtRyjfD6qqA/Bfd2pDC... 2 - https://github.com/lihaoyi/workbench-example-app/blob/todomv...
This could result in code duplication, but the end result is the same: a complete state of the application can be rendered server-side and then can evolve independently on the client side.
I currently do this too - I'll add that it is helpful to use a templating language that will work both server side and client side so you only write your templates once.
What does become a pain is doing routers/controllers both client side and server side - end up writing some code more than once and in different languages. Harder to maintain, especially when changes are made.
Noone is saying there aren't other solutions to the problem, but I think the OP's solution met his goals pretty well and I thought it was a neat concept.
there exists templating engines that run on both server and client - for example, google closure templates.
No disagreements on multiple solutions - definitely a cool approach.
If all your content is generated by a single page web app
that downloads data and executes JS, your site won't get
crawled at all - no popular search engines executes JS.
GoogleBot does actually execute at least some javascript: https://twitter.com/mattcutts/status/131425949597179904 http://googlewebmastercentral.blogspot.com/2011/11/get-post-... and http://www.jefftk.com/p/googlebot-running-javascriptI'm asking because my product has what I call "Smart Attributes" which are basically programmable context aware metadata. These "Smart Attributes" are designed to be attached to a Git commit, GitHub pull request, diff lines, etc. and can be programmed in JavaScript to react to what it is attached to.
In the beginning I gave the user the ability to execute their Smart Attribute scripts on the server side but I eventually removed that option because I didn't have the time to fully think it through. Basically I was paranoid about missing something that would allow them to do dangerous things on the server. This was a couple of years ago and I was using Rhino from Mozilla.
Now that Nashorn is available, I've been thinking about JavaScript server side execution again, and was wondering if there were any best practice sandboxing methods and/or libraries. If anybody knows of any good documentation or libraries for sandboxing in Nashorn, I would love to hear about it.
Google and the other search engines should go with the times and start to render and index single page js applications just like they index html pages. Executing js on the server and get the resulting output is a solved problem. JS is enabled by default on all browsers that matter (and very difficult to disable), I don't understand why we still have to play nice with search engines and render the html on the server as well just for them.
Any idea then why people keep saying¹ that "Serving HTML from the server is great for search engines"?
And why should we use this² when google is perfectly capable of executing the js and get the html output all by itself?
¹[citation needed]
²https://developers.google.com/webmasters/ajax-crawling/docs/...
If I recall correctly, Twitter had this problem. The size of their apps + templates bloated to 2MB or so - making that initial page load pretty bad.
Browsers have become extremely complex beasts. It is very difficult to simulate one using anything but the original browser code. So my bet is still on phantomjs.
I firmly believe that search engines will have to execute JavaScript as well (if they don't already do it). I think this is just Google's attempt to put off the inevitable for a little while longer: https://developers.google.com/webmasters/ajax-crawling/docs/...
Any reason not to do this? (we're on Mono, not JVM but there's plenty of C# JS engines too
In order to exploit that vulnerability, improper string concatenation is the most used technique (see SQL injection).
var untrustedURL = 'x" onerror="alert(1)';
document.body.innerHTML += '<img src="' + untrustedURL + '">';
In React, you don't use string concatenation to build the Virtual DOM. This way you cannot fool React into setting properties that the developer didn't explicitly let you. React.renderComponent(document.body, <img src={untrustedURL} />);
React.renderComponent(document.body, React.DOM.img({src: untrustedURL}));
Another advantage is that each value in React world is typed. It is either a string which is always escaped, or a component. You cannot turn a string into a component unless the developer explicitly let you.React has been designed with security in mind and prevents by default a large amount of attack vectors that exist in the browser environment.