Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

client_side_validations uses synchronous ajax #226

Closed
morganchristiansson opened this Issue Nov 22, 2011 · 8 comments

Comments

Projects
None yet
4 participants

From the jQuery documentation:
http://api.jquery.com/jQuery.ajax/

Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active.

Here's an article microsoft wrote about it:
http://blogs.msdn.com/b/wer/archive/2011/08/03/why-you-should-use-xmlhttprequest-asynchronously.aspx

8.4% of all hangs in IE9 in the past month are caused by XMLHttpRequest objects blocking the UI thread with a synchronous request. That’s a huge number! With some manageable code changes, these hangs can be avoided, and developers can give their users a better experience across their websites.

Which inspired a discussion on reddit about synchronous requests: http://www.reddit.com/r/programming/comments/j89cj/84_of_all_hangs_in_ie9_in_the_past_month_caused/

It's noticeable when using as the browser momentarily freezes while typing, it also looses keypresses when i try to tab between the text fields quickly.

I started a refactoring to address this in my fork, please have a look and see what you think.

morganchristiansson/client_side_validations@19f72ee#diff-1 .

It's very much a work in progress. I haven't finished the logic in validateElement() yet, all validator tests need to be refactored to use callbacks so there's 64 test failures. I thought I'd ask your opinion on it first before doing this.

Maybe there's an easier way, the remote callback could be called differently as there's only 1 instead of refactoring all local validators to use callbacks. But this obviously breaks the .all() function.

I'm gonna spend a bit more time on it I'll update this ticket in a bit.

Ok I did the same thing but only for the remote validators. There's 2 or 3 test failures which I'm not sure why they're happening. Some event seems to not get run somewhere. Also the ajax is still synchronous, once the callback refactoring is finished it should be easy to switch it to async. And I haven't tested it in an actual form yet, just the QUnit tests.

branch: https://github.com/morganchristiansson/client_side_validations/commits/refactor2
commit: morganchristiansson/client_side_validations@d7c7b3a

bcardarella, I'd like your feedback on my early changes on whether you agree with this change and am willing to accept my final changes to make the ajax call asynchronous using callbacks.

Thanks.

Also I'm most interested of whether you agree with the way I've implemented callbacks than code style etc. I'm happy stay consistent with any code standards you've used etc.

I'd definitely support the development of this feature - the hang on the uniqueness test is a really messy. I will try to check out your branch if/when I get the chance.

Cool dapbot, it's nowhere near finished though, but I think it's a good start.

An easier way might be to just remove uniqueness validations? Most of the time it's not that critical to this check client side.

Contributor

bcardarella commented Jul 10, 2012

I'm sorry I let this go stale. I am very interested in picking up where this left off if anybody is interested.

Contributor

bcardarella commented Feb 24, 2013

We need to use jQuery promises for the validators.

Contributor

tagliala commented Jan 20, 2017

I would like to switch to promise-based validators

This was referenced Jan 20, 2017

@tagliala tagliala added a commit that referenced this issue Jan 20, 2017

@tagliala tagliala Remove Uniqueness middleware
The Uniqueness middleware:
- Is insecure
- Is subject to brute force attacks
- Badly performs because of synchronous Ajax calling
- Did not work with mysql2 adapter

This commit also wipes the middleware

Close: #512 #597 #612 #659 #226
7c752a3

@tagliala tagliala added this to the 7.0.0 milestone Jan 20, 2017

@tagliala tagliala added a commit that referenced this issue Jan 20, 2017

@tagliala tagliala Remove Uniqueness middleware
The Uniqueness middleware:
- Is insecure
- Is subject to brute force attacks
- Badly performs because of synchronous Ajax calling
- Did not work with mysql2 adapter

This commit also wipes the middleware

Close: #512 #597 #612 #659 #226
2cf97b2

@tagliala tagliala added a commit that referenced this issue Jan 20, 2017

@tagliala tagliala Remove Uniqueness middleware
The Uniqueness middleware:
- Is insecure
- Is subject to brute force attacks
- Badly performs because of synchronous Ajax calling
- Did not work with mysql2 adapter

This commit also wipes the middleware

Close: #226 #512 #597 #612 #659 #636
8b40f19

@tagliala tagliala self-assigned this Jan 21, 2017

@tagliala tagliala closed this in 35501c1 Jan 22, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment