• Resolved Tecca

    (@tecca)


    I’m writing an Nginx tutorial on my site, which uses W3 Total Cache, and writing <pre><code> stuff here </code></pre>.

    The plugin replaces this:

    	location = /favicon.ico {
    		log_not_found off;
    		access_log off;
    	}

    With this:

    	location =https://cdn.example.com/favicon.ico.gzip {
    		log_not_found off;
    		access_log off;
    	}

    When I disable the plugin and preview the post again, it doesn’t replace it. For full disclosure, I’m using the Highlighting Code Block plugin to add my code to posts, which uses Prism.js, but I don’t think that would be the conflict here.

    It makes sense that W3TC changes the URLs in posts, particularly for assets/images that are served through the CDN. It doesn’t make sense to do so in code blocks, however. Is there a setting that I’m missing that I can use to stop this from happening? But while also keeping things like images using the CDN links.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @tecca

    Thank you for your inquiry and I am happy to assist you with this.
    That W3TC does is rewriting the URLs of the assets that are uploaded to the CDN, in your case https://cdn.example.com/favicon.ico, and this is what you are seeing in the source of your website. So, the resource is now being served from the CDN and this is why you are seeing this.
    The way around this is to exclude specific assets from being served by the CDN. However in this case, of course, you will get back the relative link, but the asset will not be served from the CDN.
    Are you experiencing any issues or 404 errors?
    Thanks!

    Thread Starter Tecca

    (@tecca)

    Thanks for the reply, Marko.

    It makes sense that W3 Total Cache would replace assets with the CDN links, but is there any relevance to replacing them in code blocks? A resource is not trying to be displayed, rather it’s a literal string of text inside of a code block.

    So if you’re writing an article or tutorial on your website and typing text like /favicon.ico inside of pre/code HTML elements, W3 Total Cache replaces the text — but the literal string is needed to write a proper tutorial, not the replacement that W3TC imposes, which would end up being https://cdn.example.com/favicon.ico.gz — making the reader confused and unable to simply copy/paste your code.

    The question is more so “why does W3TC replace strings inside of code blocks and is there a way to stop that from happening without turning off CDN options?” I can’t see why it would be helpful to replace assets inside of code blocks because they are not meant to be displayed as assets, just text. Seems it would be considered a bug than part of the feature set.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘W3CT is replacing relative link in pre/code blocks’ is closed to new replies.