Lỗi: Không sử dụng trình nghe bị động để cải thiện hiệu suất cuộn trong wordpress

Thảo luận trong 'Lập trình website' bắt đầu bởi seolagi, 25/12/20.

  1. seolagi

    seolagi

    Moderator

    Thành viên BQT

    Tham gia ngày:
    16/4/14
    Bài viết:
    957
    Đã được thích:
    77
    Điểm thành tích:
    28
    HI mọi người, em kiểm tra web em làm bằng wodpress themes flasome kiểm tra tốc độ tại developers.google.com/speed/pagespeed/insights/ thì bị báo lỗi

    Lỗi: Không sử dụng trình nghe bị động để cải thiện hiệu suất cuộn wordpress

    Lỗi này là gì vậy? bạn nào biết giúp mình với, tự nhiên bị lỗi này không hiểu là do cái gì cả. Cảm ơn
     
    Cảm ơn đã xem bài:

    Lỗi: Không sử dụng trình nghe bị động để cải thiện hiệu suất cuộn trong wordpress

  2. admin

    admin Phạm Công Sơn Thành viên BQT

    Tham gia ngày:
    22/5/13
    Bài viết:
    4,618
    Đã được thích:
    1,130
    Điểm thành tích:
    113
    Giới tính:
    Nam
    Bạn chèn code sau vào function.php của themes là vượt qua được lỗi đó nhé:
    PHP:
    function add_script_fix_devgg(){ ?>
        <script>
          (function() {
            var supportsPassive = eventListenerOptionsSupported();
            if (supportsPassive) {
              var addEvent = EventTarget.prototype.addEventListener;
              overwriteAddEvent(addEvent);
            }
            function overwriteAddEvent(superMethod) {
              var defaultOptions = {
                passive: true,
                capture: false
              };
              EventTarget.prototype.addEventListener = function(type, listener, options) {
                var usesListenerOptions = typeof options === 'object';
                var useCapture = usesListenerOptions ? options.capture : options;
                options = usesListenerOptions ? options : {};
                options.passive = options.passive !== undefined ? options.passive : defaultOptions.passive;
                options.capture = useCapture !== undefined ? useCapture : defaultOptions.capture;
                superMethod.call(this, type, listener, options);
              };
            }
            function eventListenerOptionsSupported() {
              var supported = false;
                try {
                var opts = Object.defineProperty({}, 'passive', {
                  get: function() {
                    supported = true;
                  }
                });
                window.addEventListener("test", null, opts);
              } catch (e) {}
              return supported;
            }
          })();
        </script>
      <?php 
    }
    add_action('wp_footer''add_script_fix_devgg');
     


Like và Share ủng hộ ITSEOVN