Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Asset Class and CDN support
  • Hi, Page load times are an important metric for me so I'm planning to deliver my static files (assets) via CDN. Initially, I don't plan using a CDN provider; but rather use my own server and domain, like: fuelstatic.com (no cookie domain with nginx webserver for fast static content delivery.) Fuel's Asset Class is useful; however doesn't support redefining the basepath of the assets - or does it? Should I configure it (with a method like "set_path") so that all assets' links start with http://www.fuelstatic.com/ Or better, even support protocol-relative URLs as explained in this article: http://paulirish.com/2010/the-protocol-relative-url/ In this scenerio, we'll set the basepath like this:
    // returns < img src="//fuelstatic.com/img/logo.png" id="logo" >
    Asset::set_path('fuelstatic.com');
    echo Asset::img('logo.png', array('id' => 'logo'));
    
    Such a feature would also support many CDN providers (considering the fact that we rsync the assets to our static domain or use the CDN's API.) Is this possible with Fuel or will it be considered to be added? Thanks
  • Is it possible to set the basepath of the assets; a) by extending the Asset Class?
    b) by configuring any of the config files that are already built-in? Thanks.
  • At the moment, the asset class supports locating assets in local file paths using Asset:add_path(), and requires your assets to be structured a specific way. Alternatively, you can pass a URI to Asset::js() and Asset::img(), which will be used without validation. So you can use a CDN at the moment, but you have to make that decision when you call the Asset class. You could always extend the Asset class, but I fear it's going to be complicated, because you would want to make the CDN yes/no decision on a per file basis. If you build this into the Asset class, it's going to be true for all assets of a given type.
  • Hi WanWizard, thanks for your reply. Actually what I'm looking is NOT a complicated solution, but rather a simple approach/flexibility to the core Asset Class. And it is to be able to "set the basepath" globally. Likewise no database classes, and or ORMs force you to use a specific database name, user name, password; we'll be able to set the basepath and img/css/js directory names - without hacking the core or even preferably without extending it for those reasons (for better performance.) So, I doubt anyone will need to use a different basepath per file bases. For special cases, setting different basepaths per "group" basis or per "filetype" basis MAY be needed. Example #1: A CSS "static" group may be served from the local filepath, while all other CSS is served from the external server/CDN. Example #2: All JS files will be delivered from the local filepath, while all CSS and IMG files are served from the external server/CDN. But again, all of this can be global settings and/or can be set within controllers - in the same way ::add_path and::remove_path can be used within controllers. Actually, I took a look at the \core\classes\asset.php file, and it sets the $_asset_paths, $_asset_url and $_folders and I know how to extend this Class - however I'm not sure if these can be configured as well in a similar way most of the settings of the Core Fuel can be configured. Init comment of the Asset Class has this line: "Loads in the config and sets the variables" Which makes me wonder; but I'm no expert of understanding this without documentation. Thanks!
  • You can set the basedir globally, its in the asset config file, the 'url' parameter. If no app/config/asset.php file exists, fuel/core/config/asset.php is loaded, which sets 'url' to the applications base_url.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion