Home > unix/linux > JSC JavaScript Collection

JSC JavaScript Collection

August 24th, 2008 Leave a comment Go to comments

JSC JavaScript Collection

We need jsmin and gzip, compile the jsmin.c:

gcc -o jsmin jsmin.c

Script to generate a collection of the javascript files:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash
 
echo "JavaScript Collection"
 
  EXPECTED_ARGS=1
  E_BADARGS=65
 
if [ $# -ne $EXPECTED_ARGS ]
then
  echo "Usage: `basename $0` {path of the javascripts}"
  exit $E_BADARGS
fi
 
# Join the javascript scripts in one file
cat $1/*.js >> $1/.__fullscripts.tmp
 
# use JSMIN to minifier the script
cat $1/.__fullscripts.tmp | jsmin > $1/.__fullscripts.min.tmp
 
# awk remove the first blank line, gzip compress the script
awk 'FNR>1{print}' $1/.__fullscripts.min.tmp | gzip > $1/collection_scripts.js.gz
 
# remove temporal files
rm $1/.__fullscripts.tmp $1/.__fullscripts.min.tmp

Howto: jsc public_html/web/js/

Now create one php script to replace all javascripts:

<script type="text/javascript" src="collection_scripts.php"></script>

Content of collection_scripts.php:

<?php
    header("Content-type: text/javascript; charset: UTF-8?");
    header("Content-Encoding: gzip");
    readfile("collection_scripts.js.gz");
?>
Categories: unix/linux Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Switch to our mobile site