How to optimize jQuery to run on asp.net web form updatepanel? I wrote this Jqeury to make it work with asp.net update panel. I know i do little bit of hacking to make it work just. I want to get some help in how to optimize and remove the hacks from my script.

&lt;script type="text/javascript"&gt;

    //get all elemnt with class .resource-download
    $.each($(".resource-download"), function () {
        var fileExtension = getFileExtension(this.href);
        if (fileExtension == "" || fileExtension != "pdf") {
            $(this).addClass("hideLinke");
        }
    });

    //load script agine 
    function init() {
        $.each($(".resource-download"), function () {
            var fileExtension = getFileExtension(this.href);
            if (fileExtension == "" || fileExtension != "pdf") {
                $(this).addClass("hideLinke");
            }
        });
    }

    // getFileExtension 
    function getFileExtension(fileURL) {
        if (fileURL.indexOf('.') === -1) { return ""; } //check for no extension
        return fileURL.split('.').pop();
    }

    //loadGridLayout
    function loadGridLayout() {
        $('#grid-wrapper').masonry();
        $('.selectpicker').selectpicker();


        $('.btn-hamburger').click(function () {
            $('.lts-nav').toggleClass('expanded');
            $('.wrapper').toggleClass('wrapper-expanded');
        });



        /* iPhone Site Search Styling */
        var searching = false;

        $('.search-add-on').click(function () {
            if ($(window).width() &lt; 480) {
                $('.section-1 .search-hideable').toggle();
                $('.section-1 .site-search').focus();
                searching = true;
            }
        });

        $('.site-search').blur(function () {
            if ($(window).width() &lt; 480) {
                $('.section-1 .search-hideable').toggle();
                searching = false;
            }
        });

        $(window).resize(function () {
            if ((searching || !$('.site-search').is(':visible')) &amp;&amp; $(window).width() &gt; 480) {
                $('.section-1 .search-hideable').toggle(true);
                $('.section-1 .search-hideable').removeAttr('style');
                searching = false;
            }
        });
    }
    //add script to script manager
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(init);
    prm.add_endRequest(loadGridLayout);

&lt;/script&gt;
Some notes in no particular order:

1

//get all elemnt with class .resource-download
$.each($(".resource-download"), function () {
    var fileExtension = getFileExtension(this.href);
    if (fileExtension == "" || fileExtension != "pdf") {
        $(this).addClass("hideLinke");
    }
});

//load script agine 
function init() {
    $.each($(".resource-download"), function () {
        var fileExtension = getFileExtension(this.href);
        if (fileExtension == "" || fileExtension != "pdf") {
            $(this).addClass("hideLinke");
        }
    });
}


better to define the function and call it rather than copy paste the code. 

function init() {
    $.each($(".resource-download"), function () {
        var fileExtension = getFileExtension(this.href);
        // see point 2
        if (fileExtension == "" || fileExtension != "pdf") {
            $(this).addClass("hideLinke");
        }
    });
}

init();


2

if (fileExtension == "" || fileExtension != "pdf") {


Is pointless, "" !== "pdf" so you should just have the second condition.

if (fileExtension !== "pdf") {


3
It's better to be in the habit of using === and !== to avoid subtle bugs caused by type coercion.

4

$.each($(".resource-download"), function ()  {}); is better written as $(".resource-download").each(function() {});