Optimized URL
-
Previously, I use free cdn from optimole, all urls work fine including optimized urls.
Then use statically.
But, statically does not replace optimized url with cdn url.I’ve tested it with 3 plugins:
– Autoptimize
– WP-Optimize
– LiteSpeed CacheSo, I add code in function.php or with Code Snippets plugin to fix it.
Example for LiteSpeed Cache plugin:
- goto: LiteSpeed Cache -> CDN -> Use CDN Mapping -> CDN URL
- paste: https://cdn.statically.io/FILE_PATH/yourdomain.com/
- click: Save Changes
- goto: Appearance -> Theme Editor -> functions.php
- paste this code
// Modify output LiteSpeed CSS & JS URL after applying CDN rules add_filter( 'litespeed_buffer_after', function( $content ) { function replaceCssJs( $type, $tag, $data ) { $pattern = '/(<'. $tag .'[^>]+)file_path(\/[^\/]+\/[^\/]+\/litespeed\/(css|js|cssjs)\/[^\.]+\.('. $type .')[^>]+>)/i'; if ( preg_match($pattern, $data) ) { if ($type == 'css') { // css injected above the closing </head> tag preg_match($pattern, $data, $css); $data = preg_replace($pattern, '', $data); $data = str_replace('</head>', $css[0] .'</head>', $data); } $data = preg_replace($pattern, '$1$3$2', $data); } return $data; } $content = replaceCssJs('css', 'link', $content); $content = replaceCssJs('js', 'script', $content); return $content; } );
- click: Update File
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Optimized URL’ is closed to new replies.