Quantcast
Channel: Lil Josh » PHP
Viewing all articles
Browse latest Browse all 11

Combining Javascript Files to Reduce HTTP Requests

$
0
0

I just wanted a very basic PHP script to combine all my JS files into one – no minification, just bring them together into one file.

<?php
// compress the file using GZIP
ob_start("ob_gzhandler"); 

// javascript content-type
header('Content-type: text/javascript');

// define the files you want to combine
$files = array('jquery.js', 'app.js', 'somePlugin.js');

// combine the files
foreach($files as $file) {
    // get the contents of this file
    $content .= file_get_contents($file) . '
'; //add a new line
}

// output the contents
echo $content;

?>

Viewing all articles
Browse latest Browse all 11

Trending Articles