Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/const.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
}
16 changes: 16 additions & 0 deletions src/admin-settings.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
39 changes: 19 additions & 20 deletions src/cdn.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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.
Expand All @@ -234,6 +232,7 @@ public function finalize( $content ) {
$this->content = $content;

$this->_finalize();

return $this->content;
}

Expand Down