Simple CSS/JS concatenation with PHP: Pro's and cons?
I always develop remotely, and I usually end up with one big main.css and
main.js file. The bigger he projects, the more jumbled up things get. So
I've been wanting to split up the .css and .js files for increased
modularity. But I wouldn't want to have a ton of http requests with
loading all these different files. And excellent software like Codekit
on't really work for me given my remote dev workflow.
So I came up with this basic setup:
<html>
<head>
<style>
<?php
$css = file_get_contents('css/a.css').
file_get_contents('css/b.css').
file_get_contents('css/c.css');
$css = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css); //
remove comments
$css = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', '
'), '', $css); // remove tabs, spaces, newlines, etc.
echo $css;
?>
</style>
</head>
<body>
<p>Hello.</body>
<script>
<?php
$js = file_get_contents('js/a.js').
file_get_contents('js/b.js').
file_get_contents('js/c.js');
echo $js;
?>
</script>
</body>
</html>
What I like about this approach is the modularity of the files, the single
http request (only the html file itself) and the fact that everything
happens automatically and without messing with the workflow.
What do you guys think about this?
No comments:
Post a Comment