The drawback is that the downloaded
combine.php must be adjusted and that all
combined files must exist in the same folder. It’s not a big problem, but since
folder, I want to be able to provide the bundle URL with full paths to the files
I want to bundle.
Since the original solution was so slick, this was quite easy to achieve. This is basically how I did it:
- In your project root, create a folder called
bundle(or whatever you want).
- In the bundle folder, create an
.htaccessfile and add the following code:
- RewriteEngine On
- RewriteBase /
- RewriteRule ^css/(.*.css) /combine.php?type=css&files=$1
- In the bundle folder, create a
combine.phpfile and add this content to it.
Now you’re practically at where the original approach told you to adjust the PHP code. Instead, do this:
$path = realpath($base . '/' . $element);
with this code:
$path = "../" . $element
The code has to be replaced at two places in the php file, but that’s it! The only thing to consider now, is to use application root relative paths when calling the bundle URL.
For instance, I have my main js folder in the root folder
content/js. Let’s say
that I have the files
b.js in this folder. The bundle URL would then be:
To bundle css files, the corresponding code would look like:
The adjusted code will add a ../ to each link before parsing the file. This will
still work great, since
combine.php is placed one level down from the application
root, to which the links have to be relative.
Another nice thing is that the
.htaccess file is placed inside the bundle folder,
which means that you can just copy the bundle folder to use it in another project.