Search

bbPress Showcase » bbpress bbPress Chat

trick to make relative URLs instead of full absolute URI

RSS

  1. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 330

    offline

    It was really bothering me how a page full of links was wasting so many bytes on full absolute URI's with the domain name, etc. when all it needed was a tidy relative URL. The front page alone is 4k bigger just because of all the full URIs on the tag cloud and views, etc.

    ie. http.//www.bbpress.org/forums/forum/plugins
    vs. /forums/forum/plugins
    (multiply that by a few hundred)

    So it dawned on me just now that it's fairly easy using filters to make all the urls relative. Just for safety, we don't kick in the relative URLs until bbPress has gotten past the header section of the template. This makes sure that redirects, stylesheets, and javascript is handled properly.

    function bb_relative_uri($r) {return "/forums/";} // change forums to your path
    function bb_relative_domain($r) {return "";}
    function bb_relative() {
    add_filter( 'bb_get_option_domain','bb_relative_domain',255);
    add_filter( 'bb_get_option_uri','bb_relative_uri',255);
    } add_action('bb_head', 'bb_relative',255);

    .
    In some cases, relative URLs actually makes Internet Explorer cache better
    so this may be helpful for subtle speedups too.

    I haven't discovered anything broken by this yet
    but be sure to let me know if you run into anything.

    Posted 7 months ago #

RSS feed for this topic

Post a reply to “trick to make relative URLs instead of full absolute URI”

You must log in to post.

keep _ck_ coding >> donate $1 <<     Theme Switcher:
16 users online from  US  BE  IN  CN in the past 30 minutes. 10 bots 6 guests
396 views today 2798 yesterday 3411 ever. Most at once 19 today 24 yesterday 19 ever. Visited today: _ck_
724 posts in 106 topics over 19 months by 146 of 676 members. Latest: nicoosuna, Wish, insightdesigns