{"id":712,"date":"2024-05-07T11:42:00","date_gmt":"2024-05-07T11:42:00","guid":{"rendered":"https:\/\/kb.shortpixel.com\/docs\/can-i-use-a-different-cdn-with-your-service\/"},"modified":"2025-08-27T08:46:19","modified_gmt":"2025-08-27T08:46:19","password":"","slug":"can-i-use-a-different-cdn-with-your-service","status":"publish","type":"docs","link":"https:\/\/kb.shortpixel.com\/knowledge-base\/article\/can-i-use-a-different-cdn-with-your-service\/","title":{"rendered":"Can I use a different CDN with Autoptimize?"},"content":{"rendered":"<div>\n\t<em><strong>Important note<\/strong>: Autoptimize&nbsp;works correctly out-of-the-box, so configuring it to work with your own CDN should only be done if you have <strong>good technical knowledge<\/strong>.<\/em>\n<\/div>\n<p>\n\t If you want to use a different CDN than the default <strong>sp-ao.shortpixel.ai<\/strong> when serving optimized images with Autoptimize, then please:<\/p>\n<ol>\n<li><strong>Edit your <\/strong><a href=\"https:\/\/en.wikipedia.org\/wiki\/Domain_Name_System\" rel=\"noopener\"><strong>DNS records<\/strong><\/a> to&nbsp;add a <a href=\"https:\/\/en.wikipedia.org\/wiki\/CNAME_record\" rel=\"noopener\">CNAME<\/a> from <code>cdn.example.com<\/code> to <code>no-cdn.shortpixel.ai<\/code>. This step might be slightly different depending on what CDN you use. Below you can see an example, but&nbsp;<strong>we recommend you to contact your CDN provider so they can help you set this up<\/strong>.\n<ol>\n<li>On the previous URL, replace <code>example.com<\/code> with your actual domain name.<\/li>\n<li>If <code>cdn.example.com<\/code> is already being used on your DNS records, you can change it to whatever you want, like <code>images.example.com<\/code> or <code>img.example.com<\/code>.<\/li>\n<\/ol>\n<\/li>\n<li><strong>Make sure<\/strong> the new record (cdn.example.com) works as expected with an online tool like <a href=\"https:\/\/www.whatsmydns.net\/\" rel=\"noopener\">whatsmydns.net<\/a>.<\/li>\n<li><strong>Add the following code snippet<\/strong> to your functions.php file. You can use a plugin like <a href=\"https:\/\/wordpress.org\/plugins\/code-snippets\/\" rel=\"noopener\">this<\/a> one.\n<pre>add_filter(\"autoptimize_filter_imgopt_base_url\",\"use_my_own_cdn\");\nfunction use_my_own_cdn($urlIn) {\n\t return str_replace(\"sp-ao.shortpixel.ai\",\"cdn.example.com\",$urlIn);\n}\n\t<\/pre>\n<p>\n\t\t Remember that you will need to change <code>cdn.example.com<\/code> to the new URL you just created, replacing <code>example.com<\/code> with your domain and <code>cdn<\/code> with the CNAME you chose.\n\t<\/p>\n<p>\n\t\t <strong>Note: <\/strong>the filter name changed since version 2.5 of Autoptimize.\n\t<\/p>\n<\/li>\n<\/ol>\n<h2>Example &#8211; Cloudflare<\/h2>\n<p>\n\t<if><\/if><\/p>\n<p>\n\t <em>Note:&nbsp;<\/em><em>If you&#8217;re having SiteGround as your hosting provider you&nbsp;<strong>cannot&nbsp;<\/strong>properly set Cloudflare and use it as a CDN together with ShortPixel Adaptive Images. For more information, visit this page:&nbsp;<\/em><a href=\"https:\/\/help.shortpixel.com\/article\/258-cdn-via-cloudflare-for-websites-hosted-at-siteground-it-this-possible\" rel=\"noopener\"><em>CDN via Cloudflare for websites hosted at SiteGround, it this possible?<\/em><\/a><\/p>\n<p>\n\t<if><br \/>\n\tHere is a step-by-step example of how to set up the CNAME (previous step 1) on<br \/>\n\t<strong>Cloudflare<\/strong>. Please notice that we are not responsible for any changes made by Cloudflare that would invalidate the following steps. Therefore, if you encounter any issues while creating your new CNAME in your DNS records, please contact Cloudflare or your hosting provider.<br \/>\n\t<\/if><\/p>\n<ol>\n<li>Enter your Cloudflare account<\/li>\n<li>Select the <strong>DNS<\/strong> section<strong>&nbsp;<\/strong>from the top menu.\n<p>\n\t\t <img decoding=\"async\" src=\"https:\/\/kb.shortpixel.com\/wp-content\/uploads\/2025\/08\/file-HvNu1xUFuV.png\">\n\t<\/p>\n<\/li>\n<li>Add a new <strong>CNAME<\/strong> record from <code>cdn.your-domain.com<\/code> to <code>no-cdn.shortpixel.ai<\/code>:&nbsp;\n<p>\n\t\t <img decoding=\"async\" src=\"https:\/\/kb.shortpixel.com\/wp-content\/uploads\/2025\/08\/file-iY1B7VKmeo.jpg\">Remember that <code>your-domain.com<\/code> should be changed to your actual domain, and that <code>cdn<\/code> should be changed to something else if it&#8217;s already being used. For example:<br \/>\n\t\t &#8211; images.myblog.com <br \/>\n\t\t &#8211; media.thebestshop.com <\/p>\n<p>\t\t <strong>The little cloud must be orange<\/strong>&nbsp;so you can use the CDN features offered by Cloudflare.\n\t<\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Important note: Autoptimize&nbsp;works correctly out-of-the-box, so configuring it to work with your own CDN should only be done if you have good technical knowledge. If you want to use a different CDN than the default sp-ao.shortpixel.ai when serving optimized images with Autoptimize, then please: Edit your DNS records to&nbsp;add a CNAME from cdn.example.com to no-cdn.shortpixel.ai. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"doc_category":[36],"glossaries":[],"doc_tag":[],"class_list":["post-712","docs","type-docs","status-publish","hentry","doc_category-autoptimize"],"blocksy_meta":[],"year_month":"2026-04","word_count":428,"total_views":"4586","reactions":{"happy":"0","normal":"0","sad":"0"},"author_info":{"name":"admin","author_nicename":"admin_mdli53m5","author_url":"https:\/\/kb.shortpixel.com\/author\/admin_mdli53m5\/"},"doc_category_info":[{"term_name":"Autoptimize","term_url":"https:\/\/kb.shortpixel.com\/knowledge-base\/category\/autoptimize\/"}],"doc_tag_info":[],"knowledge_base_info":[],"knowledge_base_slug":[],"_links":{"self":[{"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/docs\/712","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/comments?post=712"}],"version-history":[{"count":1,"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/docs\/712\/revisions"}],"predecessor-version":[{"id":2640,"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/docs\/712\/revisions\/2640"}],"wp:attachment":[{"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/media?parent=712"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/doc_category?post=712"},{"taxonomy":"glossaries","embeddable":true,"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/glossaries?post=712"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/doc_tag?post=712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}