PIX主题替换静态资源库提升网站打开速度

最近博客的前后台打开都有点慢,有时候还会抽风,通过 似水流年 推荐给我的《PIX主题替换jsDelivr公共资源库》这篇文章,成功解决了我博客目前的问题。

原文介绍的是把PIX主题引用的 jsDelivr 的静态资源公共库替换为七牛的静态资源公共库,可能是因为我这里网络的原因,我测试下来博客打开速度不升反降,所以我参照以上文章,改为引用更适合我博客的字节跳动的静态资源公共库


改造一共涉及4个文件,
分别是:


1. pix/inc/assets/codestar-framework/classes/setup.class.php

大概第575行处:

// Font awesome 4 and 5 loader
      if ( apply_filters( 'csf_fa4', false ) ) {
        wp_enqueue_style( 'csf-fa', 'https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome'. $min .'.css', array(), '4.7.0', 'all' );
      } else {
        wp_enqueue_style( 'csf-fa5', 'https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.4/css/all'. $min .'.css', array(), '5.15.5', 'all' );
        wp_enqueue_style( 'csf-fa5-v4-shims', 'https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.4/css/v4-shims'. $min .'.css', array(), '5.15.5', 'all' );
        wp_enqueue_style( 'iconfont', THEME_URL . '/inc/assets/fonts/remixicon.css', array(), '' );
      }

替换成:


// Font awesome 4 and 5 loader

      if ( apply_filters( 'csf_fa4', false ) ) {
        wp_enqueue_style( 'csf-fa', 'https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-y/font-awesome/4.7.0/css/font-awesome'. $min .'.css', array(), '4.7.0', 'all' );
      } else {
        wp_enqueue_style( 'csf-fa5', 'https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-y/font-awesome/5.15.4/css/all'. $min .'.css', array(), '5.15.4', 'all' );
        wp_enqueue_style( 'csf-fa5-v4-shims', 'https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-y/font-awesome/5.15.4/css/v4-shims'. $min .'.css', array(), '5.15.4', 'all' );
        wp_enqueue_style( 'iconfont', THEME_URL . '/inc/assets/fonts/remixicon.css', array(), '' );
      }

2. pix/inc/assets/codestar-framework/fields/code_editor/code_editor.php

大概第13行处:

public $version = '5.64.0';
public $cdn_url = 'https://cdn.jsdelivr.net/npm/codemirror@';

替换成:

public $version = '5.64.0';
public $cdn_url = 'https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-y/codemirror/';

大概第46行处:

if ( ! wp_script_is( 'csf-codemirror' ) ) {
        wp_enqueue_script( 'csf-codemirror', esc_url( $this->cdn_url . $this->version .'/lib/codemirror.min.js' ), array( 'csf' ), $this->version, true );
        wp_enqueue_script( 'csf-codemirror-loadmode', esc_url( $this->cdn_url . $this->version .'/addon/mode/loadmode.min.js' ), array( 'csf-codemirror' ), $this->version, true );
}

替换成:

if ( ! wp_script_is( 'csf-codemirror' ) ) {
        wp_enqueue_script( 'csf-codemirror', esc_url( $this->cdn_url . $this->version .'/codemirror.min.js' ), array( 'csf' ), $this->version, true );
        wp_enqueue_script( 'csf-codemirror-loadmode', esc_url( $this->cdn_url . $this->version .'/addon/mode/loadmode.min.js' ), array( 'csf-codemirror' ), $this->version, true );
}

3. pix/inc/assets/codestar-framework/fields/map/map.php

大概第13行处:

public $version = '1.7.1';
public $cdn_url = 'https://cdn.jsdelivr.net/npm/leaflet@';

替换成:

public $version = '1.7.1';
public $cdn_url = 'https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-y/leaflet/';

大概第81行处:

    public function enqueue() {

      if ( ! wp_script_is( 'csf-leaflet' ) ) {
        wp_enqueue_script( 'csf-leaflet', esc_url( $this->cdn_url . $this->version .'/dist/leaflet.js' ), array( 'csf' ), $this->version, true );
      }

      if ( ! wp_style_is( 'csf-leaflet' ) ) {
        wp_enqueue_style( 'csf-leaflet', esc_url( $this->cdn_url . $this->version .'/dist/leaflet.css' ), array(), $this->version );
      }

      if ( ! wp_script_is( 'jquery-ui-autocomplete' ) ) {
        wp_enqueue_script( 'jquery-ui-autocomplete' );
      }

    }

替换成:

    public function enqueue() {

      if ( ! wp_script_is( 'csf-leaflet' ) ) {
        wp_enqueue_script( 'csf-leaflet', esc_url( $this->cdn_url . $this->version .'/leaflet.js' ), array( 'csf' ), $this->version, true );
      }

      if ( ! wp_style_is( 'csf-leaflet' ) ) {
        wp_enqueue_style( 'csf-leaflet', esc_url( $this->cdn_url . $this->version .'/leaflet.css' ), array(), $this->version );
      }

      if ( ! wp_script_is( 'jquery-ui-autocomplete' ) ) {
        wp_enqueue_script( 'jquery-ui-autocomplete' );
      }

    }

4. pix/inc/assets/codestar-framework/fields/typography/typography.php

大概第354行处:

wp_enqueue_script( 'csf-webfontloader', 'https://cdn.jsdelivr.net/npm/webfontloader@1.6.28/webfontloader.min.js', array( 'csf' ), '1.6.28', true );

替换成:

wp_enqueue_script( 'csf-webfontloader', 'https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-y/webfont/1.6.28/webfontloader.js', array( 'csf' ), '1.6.28', true );

转载请注明出处 © 2024 www.suibi.net

消息盒子
# 您需要首次评论以获取消息 #
# 您需要首次评论以获取消息 #

只显示最新10条未读和已读信息