• Resolved frkly

    (@frkly)


    Hello,
    I’m currently considering using the Minify HTML plugin’s relative URL conversion feature and would like to suggest some improvements for your consideration:

    (1) OGP Tag URLs
    As noted in this Stack Overflow discussion (Open Graph cannot resolve relative URL), the OGP does not support relative URLs. Therefore, URLs within OGP tags should be excluded from the relative URL conversion process.

    ogc:url a rdfs:Datatype ;
    rdfs:label “URL”@en-US ;
    rdfs:comment “A string of Unicode characters forming a valid URL having the http or https scheme.”@en-US ;

    https://ogp.me/ns/ogp.me.ttl

    (2) URLs in Comment Text
    On my blog, URLs posted in comment text are automatically displayed as links. The current relative URL conversion process also modifies the anchor text of these links, resulting bad user experiences. Example:

    1. Before conversion:
      <a >https://blog.example.com/?p=123</a>
    2. Current result:
      <a href="/?p=123">/?p=123</a>
    3. Desired result:
      <a href="/?p=123">https://blog.example.com/?p=123</a>

        Proposal:

        I propose limiting the relative URL conversion to the following attributes: href, src, srcset, action, value

        Note: The value attribute is particularly useful for elements generated by wp_get_archives, such as <option> elements.

        Additionally, implementing apply_filters() for the final HTML output would enable users to make environment-specific adjustments, greatly improving the plugin’s versatility.

        Thank you for considering these suggestions. I look forward to your response.

      Viewing 3 replies - 1 through 3 (of 3 total)
      • Plugin Author Tim Eckel

        (@teckel)

        The plugin shouldn’t be making specific exceptions for a product or service that doesn’t support relative URLs. Also, only doing relative URL conversion inside of certain tags would require a heavy-lift.

        Instead, the solution is to simply turn off the Relative URL option. That’s what the option is for, if you need the full URL, just turn off this option.

        Thread Starter frkly

        (@frkly)

        Thank you, Tim, for your response.

        Currently, the plugin’s settings page describes this option as “This option is typically safe to set to ‘Yes’.” However, if this option is incompatible with OGP tags (used by Jetpack, Yoast, All In One SEO, Rank Math, and many other SEO plugins and themes) and can cause critical errors, it is a potential issue for users who are unaware of this limitation. To address this, you could either:

        • Improve the plugin’s behavior to ensure safer operation, or
        • Clearly state on the settings page that “This feature is incompatible with many SEO plugins/themes or OGP tags and may cause critical errors.”

        Regarding the concern about the complexity of applying relative URL conversion only within specific tags, I believe it might be relatively straightforward to limit the conversion to specific attribute values (href, src, srcset, action, value). For example, the following code could be a possible implementation:

          if ( $minify_html_relative == 'yes' && isset( $_SERVER['HTTP_HOST'] ) ) {
          $host = sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) );
          $buffer = preg_replace_callback(
          '/(href|src|srcset|action|value)=(["\'])(.*?)\2'.$mod,
          function($matches) use($host) {
          return str_replace( array ( 'https://' . $host . '/', 'https://' . $host . '/', '//' . $host . '/' ), array( '/', '/', '/' ), $matches[0] );
          }
          , $buffer
          );
          }

          While this is just one approach, it seems like a relatively simple way to limit relative URL conversion to specific attributes, maintaining the existing functionality while improving safety.

          Since the primary goal of Minify HTML is to reduce file size without altering the core functionality of the HTML, limiting relative URL conversion to non-critical parts of the HTML (i.e., parts that do not cause fatal issues) aligns better with what users are likely to expect from this plugin. On the other hand, applying relative URL conversion indiscriminately, even to parts that could lead to critical problems, is probably not the behavior most users would anticipate or desire from this plugin.

          Additionally, I tested the performance of this regular expression replacement on a 680 KB HTML page in my environment, and the processing cost was only 0.0017 seconds. This demonstrates that the impact on performance is negligible, even for relatively large files.

          I hope this solution can serve as a starting point for consideration.

          Plugin Author Tim Eckel

          (@teckel)

          Remove relative domain from internal URLs is set to OFF by default, so your fears are unfounded.

          I’ve never used OGP tags and probably others as well. There’s other situations where a setting causes a problem. The solution, instead of trying to make unique solutions for every possible 3rd party tool or plugin, it so simply create a switch to turn a certain feature off, which is currently implimented. The complexity is the need for every other unique case to also be addressed, not just OGP tags (that’s just one of many).

          The solution is to simply turn off remove relative domain from internal URLs.

        Viewing 3 replies - 1 through 3 (of 3 total)
        • You must be logged in to reply to this topic.