Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: URI Exclusions for HTML Compressor #651

Closed
raamdev opened this issue Jan 7, 2016 · 10 comments
Closed

Feature Request: URI Exclusions for HTML Compressor #651

raamdev opened this issue Jan 7, 2016 · 10 comments

Comments

@raamdev
Copy link
Contributor

raamdev commented Jan 7, 2016

@renzms writes in #650 (comment)...

some site owners may choose not to use HTML Compression for certain URLs.

There should be a filter to list down specific URLs to exclude from HTML Compression.

Referencing Internal Ticket: https://websharks.zendesk.com/agent/tickets/10412

We currently have JavaScript and CSS Exclusion options in the HTML Compressor; a new "URI Exclusion Patterns" section sounds like a good idea to me.

@renzms
Copy link

renzms commented Jan 15, 2016

Step 1

  • New feature branch in the websharks/zencache-pro repo.

  • After this line add

    'htmlc_uri_exclusions',
  • After this line add

    'htmlc_uri_exclusions'        => '', // Empty string or line-delimited patterns.
  • After this line add the following:

    case 'htmlc_uri_exclusions': // Converts to regex (caSe insensitive).
  • After this line add the following:

    /*[pro strip-from="lite"]*/
    if (!defined('ZENCACHE_HTMLC_URI_EXCLUSIONS')) {
    /**
     * URI exclusions for the HTML compressor.
     *
     * @since 16xxxx First documented version.
     *
     * @var string A regular expression; else an empty string.
     */
    define('ZENCACHE_HTMLC_URI_EXCLUSIONS', '%%ZENCACHE_HTMLC_URI_EXCLUSIONS%%');
    }

Step 2

Add UI option for:

'htmlc_uri_exclusions'

After this line here

        echo '      <h3>'.__('URI Exclusions for HTML Compressor?', SLUG_TD).'</h3>'."\n";
        echo '      <p>'.__('When you enable HTML Compression above, you may want to prevent certain pages on your site from being cached by the HTML Compressor. This is where you will enter those if you need to (one per line). Searches are performed against the <a href="https://gist.github.com/jaswsinc/338b6eb03a36c048c26f" target="_blank" style="text-decoration:none;"><code>REQUEST_URI</code></a>; i.e., <code>/path/?query</code> (caSe insensitive). So, don\'t put in full URLs here, just word fragments found in the file path (or query string) is all you need, excluding the http:// and domain name. A wildcard <code>*</code> character can also be used when necessary; e.g., <code>/category/abc-followed-by-*</code> (where <code>*</code> = 0 or more characters that are NOT a slash <code>/</code>). Other special characters include: <code>**</code> = 0 or more characters of any kind, including <code>/</code> slashes; <code>^</code> = beginning of the string; <code>$</code> = end of the string. To learn more about this syntax, please see <a href ="http://zencache.com/r/watered-down-regex-syntax/" target="_blank">this KB article</a>.', SLUG_TD).'</p>'."\n";
        echo '      <p><textarea name="'.esc_attr(GLOBAL_NS).'[saveOptions][htmlc_uri_exclusions]" rows="5" spellcheck="false" class="monospace">'.format_to_edit($this->plugin->options['htmlc_uri_exclusions']).'</textarea></p>'."\n";
        echo '      <p class="info">'.__('<strong>Tip:</strong> let\'s use this example URL: <code>http://www.example.com/post/example-post-123</code>. To exclude this URL, you would put this line into the field above: <code>/post/example-post-123</code>. Or, you could also just put in a small fragment, like: <code>example</code> or <code>example-*-123</code> and that would exclude any URI containing that word fragment.', SLUG_TD).'</p>'."\n";
        echo '      <p class="info">'.__('<strong>Note:</strong> please remember that your entries here should be formatted as a line-delimited list; e.g., one exclusion pattern per line.', SLUG_TD).'</p>'."\n";
  • Submit PR.

@renzms
Copy link

renzms commented Jan 15, 2016

@raamdev
Also, noticed a grammatical error (probably me?)

here in the URI exclusion patterns explanation

... your site from be cached by a client-side browser...

should be

your site from being cached by a client-side browser

Should I just open up a new ZenCache issue for that one?

raamdev added a commit to wpsharks/comet-cache-pro that referenced this issue Jan 15, 2016
@raamdev
Copy link
Contributor Author

raamdev commented Jan 15, 2016

noticed a grammatical error

Thanks for catching that! Fixed in wpsharks/comet-cache-pro@2a6e3a7. No need to open an issue for that one.

@raamdev
Copy link
Contributor Author

raamdev commented Jan 15, 2016

Step 1 [...] Step 2

That looks great! Nice work! 😄

@jaswsinc How's this look to you?

@renzms
Copy link

renzms commented Jan 16, 2016

Updated links to use the 160103 branch

jaswrks pushed a commit to wpsharks/html-compressor that referenced this issue Jan 18, 2016
@jaswrks
Copy link

jaswrks commented Jan 18, 2016

@jaswsinc How's this look to you?

Looks fantastic! Nice work @renzms.


@raamdev Looks like there will be one additional step needed to read the list of exclusions and prevent the HTML Compressor from running whenever one of the patterns matches the current URI. I think that code should be added to the HTML Compressor itself though.

I just released a new version of the HTML Compressor to support this.
See: https://github.com/websharks/html-compressor/releases/tag/160118


@renzms Next Actions (Step 3 of this Issue)

  • After this line add the following:

    'regex_uri_exclusions'  => ZENCACHE_HTMLC_URI_EXCLUSIONS,

    This will suffice in ZenCache Pro, because the rest of the logic exists in the HTML Compressor.

@raamdev
Copy link
Contributor Author

raamdev commented Jan 21, 2016

@renzms I noticed that you added a ready for review label here. Please only use that label for Pull Requests. If something is ready for another review in a GitHub issue, please leave a comment in the GitHub issue saying as much. :-)

@renzms
Copy link

renzms commented Jan 22, 2016

@raamdev

Noted! PR submitted and ready for review.

@raamdev
Copy link
Contributor Author

raamdev commented Jan 27, 2016

Next Pro Release Changelog:

  • New Feature! The HTML Compressor now supports URI Exclusion Patterns, so you exclude specific pages or an entire series of pages from the HTML Compressor using the flexible Watered-Down Regex Syntax. Props @renzms. See Issue #651.

@raamdev raamdev closed this as completed Jan 27, 2016
@raamdev
Copy link
Contributor Author

raamdev commented Feb 22, 2016

ZenCache v160222 has been released and includes changes from this GitHub Issue. See the v160222 announcement for further details.


This issue will now be locked to further updates. If you have something to add related to this GitHub Issue, please open a new GitHub Issue and reference this one (#651).

@wpsharks wpsharks locked and limited conversation to collaborators Feb 22, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants