10

Quick CloudFlare 'new user' question for you:

BACKGROUND: The HTML pages served up by my origin server never change. All dynamic content is download via JavaScript after the page is loaded in the user's browser. The dynamic content derived by the JavaScript depends in part upon the URL's query string but the query string itself has no affect on the HTML content that's originally downloaded. The following URLs therefore all generate exactly the same HTML from the origin prior to being acted upon by JavaScript in the browser:

https://www.example.com/private/my-investments?portfolioID=296

https://www.example.com/private/my-investments?portfolioID=325

https://www.example.com/private/my-investments?portfolioID=319

QUESTION: Given that CloudFlare does not cache HTML by default, how shall I construct my Page Rules so that a single cached copy of https://www.example.com/private/my-investments?[anyValue] is returned to all users? Here's what I've tried:

"CACHE EVERYTHING:" Using the 'Cache Everything' directive causes my HTML to be cached (good) but it uses the entire query string as part of the cache key (bad). So if a user hits the following URL...

https://www.example.com/private/my-investments?portfolioID=296

...and then ten seconds later hits the same URL with a different query string, like:

https://www.example.com/private/my-investments?portfolioID=325

...CloudFlare treats that latter request as a cache MISS (cf-cache-status:MISS) and hits my origin server again. This in spite of the fact that the HTML returned from the origin is identical for both URLs.

"IGNORE QUERY STRING CACHING:" I thought for sure I'd fix this problem by selecting the "IGNORE QUERY STRING CACHING" option. But when using this option in a Page Rule, no HTML is cached at all; Only .js, .css, and .png files are cached. And once again my origin gets hit for every single call for HTML data. :(

I feel like I must be missing something obvious. Any thoughts?

UPDATE: Had an idea I want to run by you. Could I solve this problem by changing my internal URL scheme to use '#' instead of '?' So instead of a URL like...

https://www.example.com/private/my-investments?portfolioID=296

..I'd use something like:

https://www.example.com/private/my-investments#portfolioID=296

This would prevent the query string parameters from being transmitted to CloudFlare at all... What do you think?

Festus

  • Using "#" instead of "?" in the URL solved the problem. Sysops can go ahead and delete my question. – Festus Martingale Mar 11 '16 at 0:17
  • 4
    Others might learn from what you figured out here, so maybe you can provide what you did above as an answer (with a little elaboration) and accept it when you can. Thanks. – dan Mar 11 '16 at 3:43
4

(Answer added for @Festus Martingale to mark question as answered).

Replacing the ? with a # solved the problem as it prevents the query string from being transmitted to cloudflare as it appears as a hash fragment.

  • My name is Festus. I have marked this as an answer. – Festus Martingale Jan 23 '18 at 3:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.