{"id":14871053,"date":"2021-09-14T14:15:02","date_gmt":"2021-09-14T14:15:02","guid":{"rendered":"https:\/\/wordpress.org\/support\/?post_type=topic&#038;p=14871053"},"modified":"2021-09-14T14:47:21","modified_gmt":"2021-09-14T14:47:21","slug":"optimized-url","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/optimized-url\/","title":{"rendered":"Optimized URL"},"content":{"rendered":"<p>Previously, I use free cdn from optimole, all urls work fine including optimized urls.<\/p>\n<p>Then use statically.<br \/>\nBut, statically does not replace optimized url with cdn url.<\/p>\n<p>I&#8217;ve tested it with 3 plugins:<br \/>\n&#8211; <a href=\"https:\/\/wordpress.org\/plugins\/autoptimize\/\" rel=\"noopener\" target=\"_blank\">Autoptimize<\/a><br \/>\n&#8211; <a href=\"https:\/\/wordpress.org\/plugins\/wp-optimize\/\" rel=\"noopener\" target=\"_blank\">WP-Optimize<\/a><br \/>\n&#8211; <a href=\"https:\/\/wordpress.org\/plugins\/litespeed-cache\/\" rel=\"noopener\" target=\"_blank\">LiteSpeed Cache<\/a><\/p>\n<p>So, I add code in function.php or with <a href=\"https:\/\/wordpress.org\/plugins\/code-snippets\/\" rel=\"noopener\" target=\"_blank\">Code Snippets<\/a> plugin to fix it.<\/p>\n<p>Example for LiteSpeed Cache plugin:<\/p>\n<ol>\n<li>goto: LiteSpeed Cache -&gt; CDN -&gt; Use CDN Mapping -&gt; CDN URL<\/li>\n<li>paste: https:\/\/cdn.statically.io\/<strong>FILE_PATH<\/strong>\/yourdomain.com\/<\/li>\n<li>click: <strong>Save Changes<\/strong><\/li>\n<li>goto: Appearance -&gt; Theme Editor -&gt; functions.php<\/li>\n<li>paste this code\n<pre><code>\/\/ Modify output LiteSpeed CSS &amp; JS URL after applying CDN rules\nadd_filter( &#039;litespeed_buffer_after&#039;, function( $content ) {\n  function replaceCssJs( $type, $tag, $data ) {\n    $pattern = &#039;\/(&lt;&#039;. $tag .&#039;[^&gt;]+)file_path(\\\/[^\\\/]+\\\/[^\\\/]+\\\/litespeed\\\/(css|js|cssjs)\\\/[^\\.]+\\.(&#039;. $type .&#039;)[^&gt;]+&gt;)\/i&#039;;\n    if ( preg_match($pattern, $data) ) {\n      if ($type == &#039;css&#039;) {\n        \/\/ css injected above the closing &lt;\/head&gt; tag\n        preg_match($pattern, $data, $css);\n        $data = preg_replace($pattern, &#039;&#039;, $data);\n        $data = str_replace(&#039;&lt;\/head&gt;&#039;, $css[0] .&#039;&lt;\/head&gt;&#039;, $data);\n      }\n      $data = preg_replace($pattern, &#039;$1$3$2&#039;, $data);\n    }\n    return $data;\n  }\n  $content = replaceCssJs(&#039;css&#039;, &#039;link&#039;, $content);\n  $content = replaceCssJs(&#039;js&#039;, &#039;script&#039;, $content);\n  return $content;\n} );<\/code><\/pre>\n<\/li>\n<li>click: <strong>Update File<\/strong><\/li>\n<\/ol>\n","protected":false},"template":"","class_list":["post-14871053","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/14871053","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":2,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/14871053\/revisions"}],"predecessor-version":[{"id":14871141,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/14871053\/revisions\/14871141"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=14871053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}