soft-reject for CACHE JQUERY OBJECTS

themeforest

#1

here is all my jquery code:

jQuery(document).ready(function() {

    /*START PRELOADED*/
    $(window).on('load', function() {
        $('.preloader').fadeOut();
        $('.preloader-area').delay(350).fadeOut('slow');
    });
    /*END PRELOADED*/

    /*START TESTMONIAL ACTIVATION JS*/
    $(".testimonial_list").owlCarousel({
        items: 1,
        autoPlay: true,
        navigation: false,
        itemsDesktop: [1199, 1],
        itemsDesktopSmall: [980, 1],
        itemsTablet: [768, 1],
        itemsTabletSmall: false,
        itemsMobile: [479, 1],
        autoHeight: true,
        pagination: true,
    });
    /*END TESTMONIAL ACTIVATION JS*/

    /*START BLOG ACTIVATION JS*/
    $(".blog_post_inner").owlCarousel({
        items: 3,
        autoPlay: true,
        navigation: false,
        itemsDesktop: [1199, 3],
        itemsDesktopSmall: [980, 3],
        itemsTablet: [768, 2],
        itemsTabletSmall: false,
        itemsMobile: [479, 1],
        autoHeight: true,
        pagination: true,
    });
    /*END BLOG ACTIVATION JS*/

    /*START SERVICE ACTIVATION JS*/
    $(".service_list").owlCarousel({
        items: 4,
        autoPlay: true,
        navigation: false,
        itemsDesktop: [1199, 4],
        itemsDesktopSmall: [980, 4],
        itemsTablet: [768, 2],
        itemsTabletSmall: false,
        itemsMobile: [479, 1],
        autoHeight: false,
        pagination: true,
    });
    /*END SERVICE ACTIVATION JS*/

    /*START MIXITUP JS*/
    $('.portfolio_inner').mixItUp();
    /*END MIXITUP JS*/

    /*START MENU HIDE JS*/
    $(document).on('click', '.navbar-collapse.in', function(e) {
        if ($(e.target).is('a') && $(e.target).attr('class') != 'dropdown-toggle') {
            $(this).collapse('hide');
        }
    });
    /*END MENU HIDE JS*/

    /*START BOOTSTRAP SCROLL-SPY*/
    $('body').scrollspy({
        target: '.navbar-collapse',
        offset: 195
    });
    /*END BOOTSTRAP SCROLL-SPY*/

    /*COUNTER UP JS*/
    $(".counter_number").counterUp({
        time: 2000,
        delay: 10
    });
    /*COUNTER UP JS*/

    /*START MAGNIFICENT POPUP JS*/
    $('.portfolio_popup').magnificPopup({
        type: 'image',
        gallery: {
            enabled: true
        }
    });
    /*END MAGNIFICENT POPUP JS*/

    /*START CHANGE MENU BACKGROUND JS*/
    $(window).on('scroll', function() {
        if ($(window).scrollTop() > 200) {
            $('.header_top_area').addClass('strick-bg');
        } else {
            $('.header_top_area').removeClass('strick-bg');
        }
    });
    /*END CHANGE MENU BACKGROUND JS*/

    /*START SCROLL TO UP*/
    $(window).on('scroll', function() {
        if ($(this).scrollTop() > 500) {
            $('.scrollup').fadeIn();
        } else {
            $('.scrollup').fadeOut();
        }
    });
    $('.scrollup').on("click", function() {
        $("html, body").animate({
            scrollTop: 0
        }, 800);
        return false;
    });
    /*END SCROLL TO UP*/

    /*START SMOOTH SCROLL JS*/
    $('a.smoth-scroll').on("click", function(e) {
        var anchor = $(this);
        $('html, body').stop().animate({
            scrollTop: $(anchor.attr('href')).offset().top - 50
        }, 1000);
        e.preventDefault();
    });
    /*END SMOOTH SCROLL JS*/

});

First Item Soft rejected. Spacing Issues and Strick mode. Help needed
#2
  1. CACHE JQUERY OBJECTS: Please cache your jQuery selectors to improve performance: https://jsperf.com/why-cache-jquery-selectors

#3

Define window

Example

var window = $("window");  
 $(function () {
    window.addClass(foo)
 });

Also don’t forget to add ‘use strict’;


#4

Not just $(window)… Any time you use the same $(...) more than once, you should make it a variable unless there’s special circumstances.

I see a few others that must be made into variables too:

  • $('.header_top_area')
  • $('html, body')
  • $('.scrollup')

#5

baileyherbert@ thanks for replay :slight_smile:

here is my code:

/START CHANGE MENU BACKGROUND JS/
$(window).on(‘scroll’, function() {
if ($(window).scrollTop() > 200) {
$(’.header_top_area’).addClass(‘strick-bg’);
} else {
$(’.header_top_area’).removeClass(‘strick-bg’);
}
});
/END CHANGE MENU BACKGROUND JS/

    /*START SCROLL TO UP*/
    $(window).on('scroll', function() {
        if ($(this).scrollTop() > 500) {
            $('.scrollup').fadeIn();
        } else {
            $('.scrollup').fadeOut();
        }
    });
    $('.scrollup').on("click", function() {
        $("html, body").animate({
            scrollTop: 0
        }, 800);
        return false;
    });
    /*END SCROLL TO UP*/

can you tell me where i need change .

advance thanks :slight_smile:


#6

Hi…! BRAVEART3D
I got the “use strict” soft rejection.

STRICT MODE REQUIRED: All JavaScript should be written with “use strict” mode on. Please note that strict mode is scoped. For concise code it is recommended to placed on top of the Javascript file.

I have just added “use strict” on top of my main.js file. I am also using other js libraries in template. I should add this on top my other minified libraries too or just on my main.js file?


#7

Hi @GuppuBoss
Should be used in main.js where you call functions from another plugins.
read this article for better understand,
http://cjihrig.com/blog/javascripts-strict-mode-and-why-you-should-use-it/


#8

Cache the selectors.

    var $window = $( window ),
    var $scrollup = $('.scrollup'),
    var $header = $('.header_top_area');

        /*START SCROLL TO UP*/      	
        $window.on('scroll', function () {
            if ($(this).scrollTop() > 500) {
                $scrollup.fadeIn();
            } else {
                $scrollup.fadeOut();
            }
        });

And also the other.