From efe3de684316afc3c4ba25ce43b4f1af4afb04a1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 30 Apr 2012 11:52:30 -0500 Subject: [PATCH] Allow the specification of a asset base URL. --- application/config/application.php | 7 +++---- laravel/documentation/changes.md | 1 + laravel/url.php | 12 +++++------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/application/config/application.php b/application/config/application.php index 8baf172b..57b08295 100755 --- a/application/config/application.php +++ b/application/config/application.php @@ -20,10 +20,9 @@ | Asset URL |-------------------------------------------------------------------------- | - | The base URL used for your application's asset files, if you are serving - | them through a different server or a content delivery network, for - | example. If it's not set, we'll default to the application URL (above). - | Leave off the trailing slash. + | The base URL used for your application's asset files. This is useful if + | you are serving your assets through a different server or a CDN. If it + | is not set, we'll default to the application URL above. | */ diff --git a/laravel/documentation/changes.md b/laravel/documentation/changes.md index fbedc4ab..a33fd048 100644 --- a/laravel/documentation/changes.md +++ b/laravel/documentation/changes.md @@ -63,6 +63,7 @@ ## Laravel 3.2 - Added support for `HAVING` SQL clauses. - Added `array_pluck` helper, similar to pluck method in Underscore.js. - Allow the registration of custom cache and session drivers. +- Allow the specification of a separate asset base URL for using CDNs. ## Upgrading From 3.1 diff --git a/laravel/url.php b/laravel/url.php index 9c73526e..59c4f9c5 100644 --- a/laravel/url.php +++ b/laravel/url.php @@ -220,16 +220,14 @@ protected static function convention($action, $parameters) */ public static function to_asset($url, $https = null) { - - // If the URL is already well-formed, just return it if (static::valid($url)) return $url; - // If a base asset URL is defined in the configuration, use that and - // don't try and change links to http/https. - if ($root = Config::get('application.asset_url', false )) { - + // If a base asset URL is defined in the configuration, use that and don't + // try and change the HTTP protocol. This allows the delivery of assets + // through a different server or third-party content delivery network. + if ($root = Config::get('application.asset_url', false)) + { return rtrim($root, '/').'/'.ltrim($url, '/'); - } if (is_null($https)) $https = Request::secure();