Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Please note; this is NOT a duplicate of one of the other similar questions here on SO, as I clearly explain in the fifth paragraph of this question. Furthermore, it is not opinion based. I'm merely asking for the pro's and cons of the two ways of doing things, and specifically why Stackoverflow does things the way it does them.
For my website I'm building a notification similar to how it is implemented here on Stackoverflow at the top; when you click the notifications icon, a dropdown is presented with the relevant notifications.
I currently wrote my system in a way that the api call returns a list of json objects containing the notifications, and I then construct the html in javascript in the browser. But when I look at the network calls made by SO, I see that the api call here simply returns the html which is then pasted into the dropdown.
I now wonder; why does SO do it like this? In my opinion it is way more efficient to just provide the data in json instead of all the html surrounding it.
I checked out another question on this topic here: which suggests a third option; some kind of templating system, but that is a bit too much for the simple html that I want to insert. So I don't really want to consider that option. One more question on this topic talks specifically about the performance difference, which I'm not too concerned about either (maintainability and simplicity is more important for me than those couple milliseconds difference).
So my question is; is it more advantageous (for whichever reason) to supply all the html or just the json on an api call, and why?
In an ideal world, and in order to have a clear separation of concerns, a web api should return a view agnostic response. That gives you a big flexibility in several fronts
You can use the same api to serve different client technologies
Even in case you don't use different client technologies you may want to change something related to presentation and, if you return view specific content, is possible you'll need to change your api logic to adapt the response.
I pefer JSON response because:
(+) It is reusable, you can display this notifications in dropdown on top bar and inside user profile -> one api service - many different controls/elements
(+) less data transfered via http
(-) More calculations client side, but these days, even mobile devices got multiple cores, so we are talking about few miliseconds
This is an opinion and so can not be an actual answer (question will be closed soon).
JSON, The reason is that any program of any significance will grow (they always do) and your conceptual knowledge of the state will atrophe (as it always does) That means you need to be clear in your program where the truth is.
This notion of truth works best when the truth lies in the data not the template or the presentation. I've learned through experience that any code should be driven by the data. And so sending JSON data to be manipulated seperates concerns lightens the complexity of the server code and allows more flexability on the client side to render any way you wish. And when you scratch your head in 6 months wondering why that bug is there you can follow the data and not guess where the logic could be.
Human Javascript by Henrik Joreteg explains this well.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
So recently I have come across a site known as "negafinity", I had looked at it as a normal site, until someone told me that the site was programmed using just JavaScript (presumed they had looked at their .js files).
Site URL: https://negafinity.com/
So, is there any benefit in programming your website in full JavaScript? Rather than just programming it in plain HTML, CSS & JavaScript.
If there is, what are the benefits? And what are the disadvantages?
EDIT: To not make it so broad, I am looking for these main factors:
Website Loading
Programming Time
Caching
Though, I am also on the look out for other benefits/disadvantages so please state them if you feel they are necessary!
When an entire site is created solely with JavaScript, it is most likely because the final HTML and CSS (created by the JavaScript) will always need to be different based on certain conditions.
Those conditions could be something that can only be determined by what the situation is at the server.
Or, it could be based on the type or version of the client that is making the initial request (this would allow for the JavaScript to create proprietary HTML and/or CSS, but only when a certain kind of client makes the request).
Many sites rely heavily on content coming from databases (eBay is a very good example of this) and those sites will often just employ JavaScript to contact the server and get all the information needed and then construct the page based on smaller HTML templates.
In short, it allows for the entire page to be dynamically generated based on current conditions.
However, from a performance standpoint, it would be slower for pages to load this way than to have static HTML and CSS at least for the bulk of the page structure. It would most likely take considerably more time to code the page and less content would be cached.
With today's modern standards like CSS3 Media Queries, page content can be conditionally shown. And with AJAX, portions of a page can be conditionally generated as needed, rather than the entire page being built that way.
I don't think so. There's a reason why most sites use HTML or PHP with javascript.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to create my own application for monitoring traffic of my website without using any third party tools like google analytics. In which I want to log screenshots, user details, page details and cookies. So what technology should I opt so as to achieve this goal and which will be best suited and what work flow should I follow.
I've never done this kind of work previously so I'm new to this. Any help would be greatly appreciated.
The technologies I know are : javascript, nodejs, django(python).
You will have to break down your application as it is a humongous task to create something like GA.
You will have to track many user activities(click,spend time etc).so you can do that in plain js or use a cross-platform lightweight library(angular.js) that can make your life a little easy.
Now since you will have to send large set of traced data to you database with minimum latency,use Node.js in this scenario.Simple Ajax call would also work but then it would be very slow.
Now comes your database.Prefer NoSql since it suits your requirement of unstructured data ,preferrablly MongoDb which can help you with its own mapReduce,large storage capacity
.Since there will be lot of calculation involved you can use your python knowledge which can help you process data a lot faster.you can use other languages as well(eg.Go)
Your processed data and results can then be stored in Redis(which acts as a caching layer).
you can use sophisticated graphic library like d3.js,Highcharts.js for displaying Graphical data on the client-side.
There are a lot of factors that can be involved.This is just a very basic outline of what you could do.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I understand this question has been asked before, but I couldn't think of a simple definition of my problem to put in it's place. I am learning to do this informally, so I'm not exactly sure how to phrase questions/search for answers yet.
I'm trying to build a simple checklist program as I learn javascript - I'm doing this by hand without using any libraries (so no jQuery, just basic javascript). I have a functioning DOM interface getting formatted by CSS, all running in and editing the contents of a <div>, so that side of things seems fine.
I'm testing this off of my HDD and have no intention of hosting it anywhere.
Currently, I'm trying to solve my data storage problem without installing php/mysql/apache. I'd like to have each task list nested "subtasks" when selected, with one level of nesting.
To do this I'd like to create a new XML file every time I create a new task, and then append it's information to a list file (list.xml) so that I can navigate list.xml to dynamically display all the current primary tasks.
I've since learned that you cannot simply create new .xml files with javascript alone, for security reasons. While this makes sense, I'm now looking for other solutions.
What is the simplest way to store this information as it's entered? One solution I've considered is having just one XML file (so I always know what to point the script to), and using "<id>" nodes to slave subtasks to their respective primaries. This would, however, create a very long and disorganized XML file that would become cumbersome and annoying to traverse, forcing me to write a tricky method for looping through it.
Should I continue as I am to simply complete the project and help lock in my skills (it will be my first complete "program" with a gui of any kind that wasn't dictated by a guide or lesson), or should I bite the bullet and go through the annoying php install (I did this on my last tower and it was a frustrating time-consuming mess) and learn php/mysql/apache for all the server-side nonsense?
sry about tl;dr please help my pynchonesque code masters will kill me
You can't do much in web programming with only user side. Sooner or later you will have to learn also server side. And installing PHP is not so annoying. You can use wamp server. It has very simple installation.
If you're learning Javascript, I'd recommend staying with Javascript (don't jump over to PHP or some such just because it'll save you 5 minutes in configuration).
There are a number of really nice Javascript serverside frameworks that will happily write files to the file system or talk to a database for you. Node.js is currently the most popular. I don't want to start a flame war about how or why Node is superior to PHP, I'm simply saying that if you're a beginner, I wouldn't mix apples and oranges and just stay within one language.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm in the process of building and designing my first Javascript OOP web application and I'm wondering what kind of data structure / management system would be best to use. I know the interaction between Javascript and XML is good and fairly easy, but XML isn't meant to be used as a database.
Is it better to form a combination of both? Have a server-side language (PHP) generate XML and have it then be read by JS?
Or am I heading in the wrong direction with this?
Javascript itself doesn't do queries....it needs a helper like PHP, .net, or Java. It can traverse XML or JSON just fine like you say, but sending colossal XML documents with all possible data when only small amounts of the data is actually required will lead to massive overhead that will bring your app to its knees. It's the definition of lack-of-scalability.
My personal preference is JQuery Ajax talking to a PHP backend (transactions via JSON). If I'm dealing with the presentation of large datasets I'll always page the information server-side and pipeline it (load data ahead of and behind the current view to reduce transactions), and usually present in via jQuery DataTables. Grids are always your friend with large amounts of data. Again, personal preference, but I make heavy use of jQuery UI for layout and presentation, and I do write custom Javascript for the "nifty" one-off type things that come up. Again, any server language you have access to and are comfortable with will suffice, as Javascript is language agnostic.
Javascript can get out of hand in a hurry. I'd recommend that unless you have a ton of time on your hands that you focus on clean presentation via something baseline like HTML with judicious use of Javascript and CSS for progressive enhancement. Think about the user before you go crazy with motion, dynamic elements, etc. Don't forget the old adage, "80% of the people only use 20% of the functionality" Nail that 20% cleanly before going to town on flashy javascript fluff. Your users will thank you!
JSON is by far the fastest to parse, since it IS JavaScript.
Application frameworks like EXT.JS are already doing this with great success.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm wondering what the technologies and best practices are behind real time collaboration in web interfaces.
An example of this is of course Google Wave. Another is PivotalTracker.com.
I'm particularly interested in any work (frameworks, plugins, etc) people are doing with Ruby on Rails here.
I imagine it would have to use Javascript underneath at some level, but you would need a way to abstract this out. Probably polling the server periodically to see if changes have been made, and also a way to resolve conflicts if in the middle of editing something the server comes back and says someone else has updated it.
Thank you!
Wave has operational transform that has a nice property of being easily combinable. You have two users, each of them does "something" in the user interface and two "somethings" can be combined into final document. That allows you to skip the problems with conflict resolution.
A nice way to enable real-time updates to state of the app is by using Comet, which is essentially a geeky codename for keeping an alive, long standing, unterminated get/post request to the server, that server finishes and responds to when something happens on the server. It allows sending to the client instantaneous updates without having the client periodically poll.
I can't really say how to abstract this away in javascript/r'n'r, many of the underlying technical details are hard enough and application specific that no framework supports them out of the box.