Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Javascript include order vs cat [SOLVED]



John, Stephen,

Thank you for responding.

I had an "includes.js" file which kept a list of all the Javascript I needed, in order, so I went with Stephen's idea of editing that file to create the properly ordered list.

Took me a while to get the quotation marks properly escaped. Also I learned later that I could use anything as a delimiter on the sed command, which was important because the slashes I initially used were getting confused in combination with the slashes in the search string.

I ended up with this (after some other operations on the file, it ended up as "includes.txt"):

sed -i '/\/\// d' $DIR/javascript/includes.txt
sed -i "s#document.write('<script type=\"text/javascript\" charset=\"utf-8\" src=\"#$DIR/#"g $DIR/javascript/includes.txt
sed -i "s#\"></script>');##g" $DIR/javascript/includes.txt

The first line strips out comments, the next line strips out everything before the file names I want to keep and replaces it with an absolute path, and the third line takes out everything after.

Then I took John's cat command with xargs, like this:

cat $DIR/javascript/includes.txt | xargs cat > $DIR/all.js

... and presto! The newly created mega-Javascript file works like a charm! The ordering issue has been resolved.

I'm now also able to shrink it down from about 800 Kb to 500 Kb with YUI Compressor, which isn't bad. Really, though, the big time saving is simply not calling all the different Javascripts one by one when loading a page.

My site now goes noticeably faster.

Thanks, as always, to everyone for all the great help!

--
Dave M G


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links