Solved

jQuery working slow

Posted on 2014-09-23
6
219 Views
Last Modified: 2014-09-25
I have used JQuery in my page and added some libraries also. When i call jAlert on client side it works fine but when i call it on post back of page it takes a lot of time compared to calling it on client side.
0
Comment
Question by:Sudhanshum
6 Comments
 
LVL 1

Expert Comment

by:VijayBalkawade
ID: 40340866
Please share some code snippets.
0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 40340894
Where are you placing the script?

HTML parsing is sequential (from top to bottom) and script blocks are blocking.
This means that your code won't be parsed and executed until the HTML parser reaches there and any other scripts you might have before will delay the execution.

JavaScript is not slow and jQuery (that is nothing but JavaScript) performs very well.

Revise your code and explain us how and what exactly are you trying to do.

Cheers! :)
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 40340923
Please share the code as its very difficult to trace the exact issue
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 82

Expert Comment

by:leakim971
ID: 40341155
look for missing file, especially pictures.
if any, replace $(window).load by $(document).ready
0
 

Author Comment

by:Sudhanshum
ID: 40341209
The code shows how i am calling the script and what jQuery files i am using.
JQUERY-Example.zip
0
 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 500 total points
ID: 40341231
I don't like to do this like this.
Instead of injecting script calls, it's much clearer to have input hidden fields that define state.

Something like this:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <link href="Scripts/_assets/css/jquery.alerts.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/_assets/js/jquery.js" type="text/javascript"></script>
    <script src="Scripts/_assets/js/jquery.ui.draggable.js" type="text/javascript"></script>
    <script src="Scripts/_assets/js/jquery.alerts.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            var $hasErrors = $hasErrors('#hasErrors');
            if ($hasErrors.val() === 'true') {
                jAlert("error", "message", "Error");
            }
        });
    </script>

</head>
<body>
    <input type="hidden" value="<%= HasErrors.ToString() %>" />
    
    <form id="form1" runat="server">
    <div style="width: 865px; height: 92px; margin-bottom: 0px">
        <asp:Label ID="Lbl" runat="server" Text="UserName"></asp:Label>
        <asp:TextBox ID="txtUname" runat="server" style="margin-left:10px;"></asp:TextBox>
        <br />
        <asp:Label ID="LlblPass" runat="server" Text="Password"></asp:Label>
        <asp:TextBox ID="txtPass" runat="server" style="margin-left:15px;"></asp:TextBox>
        <br />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" style="margin-left:80px;"/>
    </div>
    </form>
</body>
</html>

Open in new window

The backend should be something like (sorry if the VB code is not fully correct):
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub btnSubmit_Click(sender As Object, e As System.EventArgs) Handles btnSubmit.Click
        'Calling the database here and validating values.
        HasErrors = True
        'Other functionalities
    End Sub

    Dim _hasErrors As Boolean = False
    Public Property HasErrors() As Boolean
        Get
            Return _hasErrors
        End Get
        Set(ByVal value As Boolean)
            _hasErrors = value
        End Set
    End Property

End Class

Open in new window

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question