Apache Django Ajax time or size limit - ajax

My ajax responses seem to die out now that I am sending so much data in response to a search form request. I'm using Django with Apache and Firefox and Chrome noth die out if I don't limit my search to few enough results. What's the time or size limit to an Ajax response?

There's no specific limit relating to AJAX. However, if you have a lot of data which you are generating, a browser will timeout if you wait to massage all of the data into a suitable form (whether JSON, XML or HTML) before sending it all out. If you are using an auto-complete type query, generally it's enough to limit the matching entries to around a dozen. If it's a more conventional search, you can use pagination for the results page. Alternatively you might need to use a generator-like approach for page generation, though that might make setting a Content-Length header a little challenging.

For a search page, do django-pagination with infinite scroll.

Related

how to implement search log?

I have a basic "input search" using AJAX (angularJS, elasticsearch and lumen) and I need to implement the search history for each user in my application. I have some ideas on this:
Save the record from the backend every time you call the uri search(maybe this would increase the response time too much).
Save each search in the frontend and when changing the pages or after a few seconds, maybe a second, send this dataset to the backend.
What would be the best way to optimize this?
For searching anyways you are calling the method , then only you can store the search history, I guess first approach is good.
Saving it at frontend first and then again one extra call for saving those search text will not be good idea.
This is my thinking.

Performance bottleneck with JSONP request (long evaluating time)

I have to use JSONP request to get large JSON (around 80kB, array of 100 object with multiple big properties). When browser is evaluating request I cant do anything with the page, browser is freezed. I suppose, JSON is evaluating and it uses UI thread.
What can I do to speed this up? Sometimes "Evaluate script" event (I use Timeline in DevTools) takes 3.5s (sic!).
I cant use regular AJAX request because of CORS, I cant enable CORS on server. I dont want to make 10 smaller requests because then I will have to rerender layout 10 times or more...

From AJAX action, returning JSON or HTML is preffered?

On my website landing page, I am calling various AJAX actions.But the performance is poor as of now.These actions are
To get latest articles
To get latest news
To get latest Jobs
To get recent added users etc.
I am showing all this information in dashboards for each AJAX actions.
My question is,
From my AJAX actions, should I return the HTML or JSON? Which one would be better in performance and maintainance point of view?
I have following few points on these approaches -
HTML
Pros-
1. Will be easy to code
2. Easy to maintain.If there is any UI change in dashboard, with HTML it would be easy to do.
Cons-
1. Performance hit as complete HTML would be sent on client side.
JSON-
Pros-
1. Good performance as data transfer size would be less.
Cons-
1. UI change in dashboard would be comparatively diffcult as I need to change JS code rendering logic.
I want to understand if my assumptions are correct or not.And if there are any other points in these approaches?
Loading and embedding HTML directly as opposed to just sending the data and transferring it into a DOM structure client-side should not be so much different when it comes to performance.
Usually the greatest performance “killer” in an HTML page environment are HTTP requests – they take close to “forever” compared to all other stuff you do client-side. So if you have to pull data for multiple such widgets, it might be a good idea to encapsulate those data transfers into just one HTTP request, and have the different widgets read their data from there once its loaded. And for that, a data format like JSON might be preferable over HTML.

GET vs. POST ajax requests: When and how to use either?

What are the strengths of GET over POST and vice versa when creating an ajax request? How do I know which I should use at any given time? Is it a security-minded decision?
Also, what is the difference in how they are actually sent?
GETs should be used for idempotent operations, that is operations that can be safely repeated more than once without changing anything. Browsers will cache GET requests (for normal and AJAX requests)
POSTs should be generally be used for non-idenpotent operations, like saving something. Although you can use them for other operations if you want.
Data for GETs is sent over the URL query string. Data for POSTs is sent separately. Some browsers have a maximum URL length (I think Internet Explorer is 2048 characters), and if the query string becomes too long you'll get an error.
You should use GET and POST requests in AJAX calls just as you would use GET and POST requests in normal calls. Basic rule of thumb:
Will the request modify anything in your Model?
YES: The request will modify (add/update/delete) data from your data store,
or in some other way change the state of the server (cause creation of
a file, for example). Use POST.
NO: The request will not affect the state of anything (database, file system,
sessions, ...) on the server, but merely retrieve information. Use GET.
POST requests are requests that you do not want to accidentally happen. GET requests are requests you are OK with happening by a user pointing a browser to via a URL.
GET requests can be repeated quite simply since their data is based in the URL itself.
You should think about AJAX requests like you think about regular form requests (and their GET and POST)
The Yahoo! Mail team found that when using XMLHttpRequest, POST is implemented in the browsers as a two-step process: sending the headers first, then sending data. So it's best to use GET, which only takes one TCP packet to send (unless you have a lot of cookies). The maximum URL length in IE is 2K, so if you send more than 2K data you might not be able to use GET.
http://developer.yahoo.com/performance/rules.html#ajax_get

ajax architecture question

I have a page with 3 layers, one for navigation, one for database records and one for results. When I click on a database record, the results are displayed in the result layer via ajax. For navigation, the links will simply be different queries. I am wondering if it would make sense to have each different query be sent as ajax data and palced into the records layer, or rather to have the query appended to the php file each time. Which is the more efficient approach?
Well, sending a different AJAX request will be recommended as per my point of view. As
Performance wise, it will rather reduce the response times, as only the POST data is sent and databytes recieved. The page can then format it, one it receives an XMLHttpResponse
Security wise : I prefer using POST than GET as it gives at least some opaqueness as to what is being passed as a parameter and not anyone can just edit the url and play around. Plus, you don't have the URL length restriction while passing parameters in POST.
So, i'd say fire an XMLHTTPRequest
each on each link and display the
response in the Results layer
(pane/div) on the page.
I think you question is quite unspecific and confusing.
What is "appended to the php file"?
Are you really concerned about efficiency? I mean, how fast should the results be displayed? Or are you concerned about the server workload?
Have you read this tutorial? Prototype introduction to Ajax
I think it should answer most of your questions and give enough example code to continue.

Resources