Need to add some custom php (setting cache headers) what is the best way?

FiftyFifty New
edited August 2015 in Vanilla 2.0 - 2.8

I need to set custom php headers to control caching, the quick & dirty way is to edit the main index.php. But that's probably not the proper way to do it ;)

What is the easiest way, to add a little code snippet, without touching the core files? Do I need to create an Addon, or are there easier ways? I've used search, but couldn't find it (although I can hardly imagine that this hasn't been asked before, so perhaps I use the wrong keywords ...)

Tagged:

Comments

  • @Fifty

    One solution would be to create a custom theme ( http://docs.vanillaforums.com/theming/quickstart/ )

    and then edit the default.master file.

    If it is a .tpl file, you would need to put the code in <literal> </literal> tags.

  • mtschirsmtschirs ✭✭✭
    edited August 2015

    editing index.php is the wrong way. The Gdn_Controller class sends its headers in the render() method. You can overwrite these headers via call to Controller->setHeader($name, $value) e.g. in a plugin viapublic function Base_render_before($sender) { $sender->setHeader(...); }

    This might be of interest to you: https://github.com/vanilla/vanilla/pull/2948

  • FiftyFifty New
    edited August 2015

    Thanks @why606 and @mtschirs, I already have my own theme (primarily for the custom css) so I'm gonna test how that works with the php header setting!

  • You probably also want to do this for static files on your server, so I would rather do this in the server rules, e.g. in .htaccess:

    Header set Cache-Control "public"
    
Sign In or Register to comment.