Cannot reproduce Ajax loading resources with relative path

Lukas W.

Well-known member
Affected version
2.0.9
The initial document loads all resources with an absolute path:
oWmePvQ.png


However, when additional resources are loaded via Ajax, they're included with a relative path:
Uko4YmK.png


That behavior is causing trouble when loading resources via Ajax to external scripts on a different subdomain.
 
I'm not able to reproduce this. Out of the box, we don't load JS with a fully absolute URL -- it will load via the "base" absolute path (/path/to/xf/js...). Ajax loaded JS does the same thing.

To test though, I set the javaScriptUrl in my config.php. Scripts now load with the full URL as expected on page load, but so do ajax scripts:
188848
You can generally see the expected paths in the XF.config.js output in the page. The URLs returned by JS needs to match that (so we don't double load).
 
Can't remember what state it was initially in when I reported that problem. By now, I'm overwriting the request.paths container to have all resources and links resolve to absolute URLs when being called from an external directory. That also causes the JS to load them with absolute paths.

Code:
$container['request.paths'] = function (Container $c) {
    /** @var \XF\Http\Request $request */
    $request = $c['request'];

    return [
        'full' => rtrim($c['options']->boardUrl, '/') . '/',
        'base' => rtrim($request->getBasePath(), '/') . '/',
        'canonical' => rtrim($c['options']->boardUrl, '/') . '/',
        'nopath' => '',
    ];
};
 
Top Bottom