The downloaded combine.php must be adjusted and all combined files must exist in the same folder.
Not a big problem, I know, but since I have a structure where css/js files may exist in sub folders, I want to be able to provide the bundle URL with full paths to the files I want to bundle.
Since the original solution is so slick, this is quite easy to achieve. I will not upload my solution for download, since I want you to grab the original code from rakaz.nl so that it receives the visitors it deserves 🙂
Well, let’s get started:
- In your project root, create a folder called bundle (or whatever you want, it is not that important)
- In the bundle folder, create an .htaccess file and add the following code:
- In the bundle folder, create a combine.php file and add this content to it.
Well, now you’re practically where the original approach tells you to adjust the PHP code a bit. Instead, do this:
In the combine.php file, replace
$path = realpath($base . '/' . $element);
$path = "../" . $element
The code has to be replaced at two places in the PHP file.
The only thing you have to consider now is to use application root relative paths when calling the bundle URL. This will cause your bundle URL to become quiiiite complex, but it works 🙂
To bundle CSS files, the corresponding code would look like:
Well, you get the point 🙂
The newly added code will add a ../ to each link before attempting to parse the file, which will work great since the combine.php file is placed one level down from the application root…to which the links have to be relative, remember?
Another great thing is that the .htaccess file is placed inside the bundle folder, which means that you can just copy the bundle folder if you want to use it in another project.
Hope this helps!