Does Backbone use etags? - backbone.js

Does Backbone use etags when fetching changes from server ?
I mean, let's say that when the initial data is loaded, it saves their etags, then when it tries to fetch changes from server, does it send the etags in the header so it will not need to download the data that is up to date ?
I hope I was clear !

Backbone uses jQuery to do ajax requests. jQuery calls the native browser APIs. The browser APIs respect etags.

Related

best practice to pass mock data to Angular & Ionic

I am working on an Ionic phone app using AngualrJs as the framework. Now I faced an issue. I don't want my app to send an HTTP request to my backend(which use Ruby on Rails) API to do a manual test.
So I'm wondering what's the best practice to pass a mock JSON data as a response when I want to call the API.
I'm not familiar with Angular and Ionic, I can find some tutorials on both sides but I don't know what's is the best practice if use them together.
You can either store the data in localStorage after the first hit and read the data from localStorage every-time whenever you need.
https://medium.com/#petehouston/awesome-local-storage-for-ionic-with-ngstorage-c11c0284d658
Or you can use
$httpBackend
https://docs.angularjs.org/api/ngMock/service/$httpBackend
by saving json files locally and injecting them back when the application tries to hit the network . One limitation here, you cannot update the json file later after the user have installed the application.
So, localStorage is preferred if you want to cache the data you have received from network.

Handle ajax Requests in Angular JS

I am working on one web application which is Single Page Application.
In that my front end will be on server and back end will be on other server.
So for each add/edit/delete/fetch operation , i need to call an Ajax request to the Back End.
There are plenty of ajax requests till now.So is there any way to handle them. I mean in angular js is there any way to do so?
FYI. I am bit new in the Angular Js.
Thanks.
You can create factories using ngResource https://docs.angularjs.org/api/ngResource or individually using make individual requests using $http service provider https://docs.angularjs.org/api/ng/service/$http. I would recommend to go for factories method. You will find this link useful if you are looking for ward to experiment it https://www.sitepoint.com/creating-crud-app-minutes-angulars-resource/

How should we support 200 screens website in backbone.js using boilerplatejs?

My application is salable. currently we identify 200 screen in my application.
In single page application we need to dump all the templates and js file in one request then initial loading takes more time to render page.
is there any standard way to handle this?
Simple!
Don't dump all templates & js file in one request. Use ajax to fetch them as & when required.
I personally prefer using requirejs

How to listen to a new document in a collection in MongoDB using AngularJS

If a users adds a new document to a collection in MongoDB, I want to listen to that change and reflect that newly entered document on a page using AngularJS without requiring the page to get reloaded again. Just like it happens in gmail or stackoverflow.
Could somebody tell me if its possible to be done using AngularJS.
I know $scope.$watch could read for changes in a scoped model in a form field.
Could somebody guide me on how it could be done, if it could be done using AngularJS?
I am using NodeJS, MongoDB, Mongoose, ExpressJS and AngularJS in my application.
For this you will probably have to use a socket connection between the server and the client, and it is not related to which JavaScript framework you are using. Sure you can implement the client-side with Angular.js (or any JavaScript framework), but you will also have to handle this in the server-side.
If you are using node.js as a server, and you want to support older browser versions, consider to use socket.io which allows you to easily establish sockets.
If not, you can use HTML5 websockets, read about it hear.

AngularJS getting data from backend

I would like to know what is the proper way to get data from backend when I want to use angularJs (or similar) in my web app?
The only way I see is to render html (static html with js scripts - e.g. angularjs) with no data from backend and then download data via ajax requests from my backend API. But I think this solution is not good because of many HTTP requests:
For example I have blog website, I want to show a post, comments, and the related posts on the sidebar. So probably I need to make at least 3 HTTP requests to get the data unless I will prepare API to get all I need in one request.
I can also imagine websites that could have much more HTTP requests. Is it a proper way to do this? Doesn't it overload a server? Or my way of thinking is so wrong?
It is either websockets or HTTP requests. Preparing API to get all in one request is one option. Another two options are XMLHttpRequest/iframe streaming which is a method of a technique known as Comet.
I would go with websockets since it is supposed to solve the problem that was previously solved with weird applications like iframe streaming. There are libraries that properly handles fallbacks if the browser does not support websockets:
web-socket-js ( this needs a websocket server )
Socket.IO ( this has a node.js module and also implements a kind of unnecessary protocol on top of websocket protocol )
If you choose the old methods there will be many problems waiting for you on the road like XmlHttpRequest.responseText while loading (readyState==3) in Chrome
I think you have to distinguish two cases:
You render the page for the first time.
You update parts of your page when something changes
Of course in the second case it makes sense to fetch only parts of the page via individual HTTP requests. However, in the first case you can simply serialize your complete model as one JSON object and embed it in the page like this:
<script type="text/javascript">
var myCompleteModel = { /* Here goes your model */ };
<script>
The controllers of the components on your page can then access this global variable to extract the parts being relevant for them. You can also wrap access to the initial model in a service to avoid accessing a global variable in all your controllers.

Resources