diff --git a/data/const.default.json b/data/const.default.json index 6a5342f8a..49209986d 100644 --- a/data/const.default.json +++ b/data/const.default.json @@ -182,6 +182,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 02c4656d0..19c158874 100644 --- a/src/admin-settings.cls.php +++ b/src/admin-settings.cls.php @@ -117,6 +117,20 @@ public function save($raw_data) foreach ($data as $k => $v) { if ($child == self::CDN_MAPPING_FILETYPE) { $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_diff($v, $remove_type); } if ($child == self::CDN_MAPPING_URL) { # If not a valid URL, turn off CDN diff --git a/src/cdn.cls.php b/src/cdn.cls.php index 87436ce16..308f09c20 100644 --- a/src/cdn.cls.php +++ b/src/cdn.cls.php @@ -95,6 +95,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); @@ -154,25 +172,6 @@ private function _append_cdn_mapping($filetype, $url) } } - /** - * If include css/js in CDN - * - * @since 1.6.2.1 - * @return bool true if included in CDN - */ - public function inc_type($type) - { - if ($type == 'css' && !empty($this->_cfg_cdn_mapping[Base::CDN_MAPPING_INC_CSS])) { - return true; - } - - if ($type == 'js' && !empty($this->_cfg_cdn_mapping[Base::CDN_MAPPING_INC_JS])) { - return true; - } - - return false; - } - /** * Run CDN process * NOTE: As this is after cache finalized, can NOT set any cache control anymore @@ -186,6 +185,7 @@ public function finalize($content) $this->content = $content; $this->_finalize(); + return $this->content; }