6

We are using CE Cache's static caching on our site because of some performance issues on our server. We are also using Freeform to place a newsletter sign up form on just about every page. Obviously this caused problems as Freeform uses the XID parameter for security purposes and when the page (and thus form) are cached it fails that security check.

We were wondering about possible options to get around this. The obvious option is to not cache the pages in that way, but the page load would behave strangely as some parts would be cached and load quickly, while other parts would take a long time to load. Some other options we considered: have that form submit to an in-between page that then does the actual Freeform submission (this seems to messy and too much overhead), have the form load in an iframe on the page (this would work except for the above issue that the whole page would load and leave that empty iframe until it loads), or move servers (ugh).

Is there any way to disable that security check for Freeform? Or is there a way around this issue? I was surprised to see that a google search on the topic didn't bring up any results, I just wanted to make sure I covered all the options before picking one. Any insights on this issue from others that may have experienced something similar?

3 Answers 3

7

I think the best way to handle that situation would be to use fragment caching on that page, instead of static caching. That way, you can cache most of the page, but escape the parts that you want to remain dynamic (see the Partial Caching documentation for more details).

Using fragment caching will still allow the page to be very fast. Not as fast as a statically cached page, but fast nonetheless. :)

Disclosure: I'm the author of the CE Cache add-on.

Edit: I actually do this on the Causing Effect site. I use the Static driver for visitors that are not logged-in, and fragment caching with the Redis driver for those that are logged-in. I don't use any static caching on the Contact page either (just fragment caching). I'm guessing I could get it to work fine, but I didn't bother with it.

4

Another option is to put your form into its own template, then use jQuery load() to load that URL on page load into a div that's included in the pages. That form template won't be cached so you will have a fresh XID each time.

<div id="subscription-form"></div>
<script type="text/javascript">
    $(document).ready(function () {
        $('#subscription-form').load('template-group/form-template');
    });
</script>

Your form goes into the "template-group/form-template" template.

2
  • 1
    Thinking this pattern is quite useful, especially where the site hosting class doesn't allow use of other than the Static method under CE Cache. Thanks for showing it, and for your mention elsewhere of the data() capability in JQuery, which I've thought might be useful in untangling some of the things people try to accomplish with Stash. Mar 1, 2013 at 16:45
  • You're welcome! It's so easy to implement too. I used it recently on a site with Varnish caching in place where I needed to have a unique piece of code always pulling fresh content.
    – Anna_MediaGirl
    Mar 1, 2013 at 17:38
0

I realized that with CE Cache it's going to need an extra condition in the .htaccess, to avoid using a cache of the requested data. No time to do it right now, but considering how to rescue a contact form that is getting rejected when not logged in as super admin, because the security code is fixed, not correct. Looks right, but isn't. Cheers, Anna.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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