'How can I make the project dropdowns in the portfolio section of my website load faster?

My website loads just fine, but when I attempt opening any of the projects in my portfolio section, it takes maybe a second too long to load - desktop & mobile.

Here's a snippet of code that I think may be causing this - I'm not sure what changes to make to fix it, please help.

Thank you

`jQuery('.portfolio-item a').on("click", function(e) {
            e.preventDefault();
            var $that = jQuery(this);
            var $item = $that.closest(".portfolio-item");
            
            if ($item.find('.loading').length===0) {
                jQuery('<div />').addClass('loading').appendTo($item);
                $that.parent().addClass('active');

                var $loading = $item.find('.loading'),
                    $container = jQuery('#portfolio-details'),
                    timer = 1;
                
                if ($container.is(':visible')) {
                    closeProject();
                    timer = 800;
                    $loading.animate({width:'70%'}, {duration:2000, queue:false});
                }

                setTimeout(function() {

                    $loading.stop(true, false).animate({width:'70%'},   
{duration:5000, queue:false});
                    
                    //Add AJAX query to the url
                    var url = $that.attr("href")+"?ajax=1";
                    
                    jQuery.get(url).done(function(response) {
                        $container.html(response);
                        
                        $container.waitForImages(function() {
                            $loading.stop(true, false).animate({width:'100%'}, 
{duration:500, queue:true});
                            
                            $loading.animate({opacity:0}, {duration:100, 
queue:true, complete:function() {
                                $that.parent().removeClass('active');
                                jQuery(this).remove();

                                $container.show().css({opacity:0}); 
                                
                                that.imageSlider($container, function() {
                                    jQuery(document).scrollTo($container, 600, 
{offset:{top:-parseInt(jQuery(".navbar").height(), 10), left:0}});
                                    $container.animate({opacity:1}, {duration:600, 
queue:false});
                                    $container.attr('data-current', 
$that.data("rel"));
                                });
                            }});
                        });`


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source