通过Lazy Load / Ajax加载插件

时间:2015-03-05 12:40:35

标签: wordpress plugins lazy-loading

HY, 我有一个用于wordpress的storelocator-plugin,大约有700个条目,这让我的网站放慢了太长时间。

是否可以延迟加载插件或在其准备好加载后显示该部分。

有什么想法吗?

THX

1 个答案:

答案 0 :(得分:0)

所以我已经检查了什么花了这么多时间来初始化:

public function _wsl_load_scripts_frontend(){

        $options = get_option( '_wsl_store_locator_settings' );
        $options = unserialize($options);

        /******************* API Settings *********************/
        $wsl_apikey = ( $options['wsl_apikey'] != "" ) ? sanitize_text_field( $options['wsl_apikey'] ) : '';
        $wsl_map_language = ( $options['wsl_map_language'] != "" ) ? sanitize_text_field( $options['wsl_map_language'] ) : 'en';

        if ( !empty($wsl_apikey) ) 
        {
          if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') 
          $wsl_apilocation = 'https';
          else 
          $wsl_apilocation = 'http';

          $wsl_apilocation .= '://maps.google.com/maps/api/js?key='.$wsl_apikey.'&sensor=false&libraries=geometry,places&language='.$wsl_map_language;
        }
        else
        {
          if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') 
          $wsl_apilocation = 'https';
          else 
          $wsl_apilocation = 'http';

          $wsl_apilocation .= '://maps.google.com/maps/api/js?sensor=false&libraries=geometry,places&language='.$wsl_map_language;
        }

        wp_register_script( 'wsl-maps-api-frontend', $wsl_apilocation );
        wp_register_style( 'wsl-store-locator-css', WPWSL_CSS.'wsl-frontend.css' );
    }