diff --git a/data/const.default.json b/data/const.default.json index 1004f0420..a0fcafbb8 100644 --- a/data/const.default.json +++ b/data/const.default.json @@ -184,6 +184,6 @@ "inc_js": ["1"], "inc_css": ["1"], "inc_img": ["1"], - "filetype": [".aac\n.css\n.eot\n.gif\n.jpeg\n.jpg\n.js\n.less\n.mp3\n.mp4\n.ogg\n.otf\n.pdf\n.png\n.svg\n.ttf\n.webp\n.woff\n.woff2"] + "filetype": [".aac\n.eot\n.less\n.mp3\n.mp4\n.ogg\n.otf\n.pdf\n.ttf\n.webp\n.woff\n.woff2"] } } diff --git a/src/admin-settings.cls.php b/src/admin-settings.cls.php index 2cdf35c84..67ab6769c 100644 --- a/src/admin-settings.cls.php +++ b/src/admin-settings.cls.php @@ -128,6 +128,22 @@ public function save( $raw_data ) { foreach ( $data as $k => $v ) { if ( self::CDN_MAPPING_FILETYPE === $child ) { $v = Utility::sanitize_lines( $v ); + // Remove from MAPPING FILETYPE extensions for IMAGES, CSS, JS + $remove_type = apply_filters( + 'litespeed_cdn_save_filetypes_remove', + array( + '.jpg', + '.jpeg', + '.png', + '.gif', + '.svg', + '.webp', + '.avif', + '.css', + '.js', + ) + ); + $v = array_values( array_diff($v, $remove_type) ); } if ( self::CDN_MAPPING_URL === $child ) { diff --git a/src/cdn.cls.php b/src/cdn.cls.php index aeca11d17..46012cc42 100644 --- a/src/cdn.cls.php +++ b/src/cdn.cls.php @@ -138,6 +138,24 @@ public function init() { } } + // Add IMAGES to rewrite if CDN Mapping setting is enabled + if (!empty($this->_cfg_cdn_mapping[Base::CDN_MAPPING_INC_IMG])) { + $add_images_type = apply_filters( 'litespeed_cdn_add_filetypes_image', array( '.jpg', '.jpeg', '.png', '.gif', '.svg', '.webp', '.avif' ) ); + foreach ($add_images_type as $ext) { + $this->_cfg_cdn_mapping[$ext] = $this->_cfg_cdn_mapping[Base::CDN_MAPPING_INC_IMG]; + } + } + + // Add CSS to rewrite if CDN Mapping setting is enabled + if (!empty($this->_cfg_cdn_mapping[Base::CDN_MAPPING_INC_CSS])) { + $this->_cfg_cdn_mapping['.css'] = $this->_cfg_cdn_mapping[Base::CDN_MAPPING_INC_CSS]; + } + + // Add JS to rewrite if CDN Mapping setting is enabled + if (!empty($this->_cfg_cdn_mapping[Base::CDN_MAPPING_INC_JS])) { + $this->_cfg_cdn_mapping['.js'] = $this->_cfg_cdn_mapping[Base::CDN_MAPPING_INC_JS]; + } + if ( ! $this->_cfg_url_ori || ! $this->_cfg_cdn_mapping ) { if ( ! defined( self::BYPASS ) ) { define( self::BYPASS, true ); @@ -200,26 +218,6 @@ private function _append_cdn_mapping( $filetype, $url ) { } } - /** - * Whether the given type is included in CDN mappings. - * - * @since 1.6.2.1 - * - * @param string $type 'css' or 'js'. - * @return bool True if included in CDN. - */ - public function inc_type( $type ) { - if ( 'css' === $type && ! empty( $this->_cfg_cdn_mapping[ Base::CDN_MAPPING_INC_CSS ] ) ) { - return true; - } - - if ( 'js' === $type && ! empty( $this->_cfg_cdn_mapping[ Base::CDN_MAPPING_INC_JS ] ) ) { - return true; - } - - return false; - } - /** * Run CDN processing on finalized buffer. * NOTE: After cache finalized, cannot change cache control. @@ -234,6 +232,7 @@ public function finalize( $content ) { $this->content = $content; $this->_finalize(); + return $this->content; }