when we use Expires header for text files like js, css, contents are cached in the browser, to get new content we need to change in the html file the new names in the link and script tag. When we add changes. How can we automate it.

I may have some bunch of html files in multiple folders also in subdirectories.

There would be a text file

filelist.txt

OldName                 NewName
oldfile1-ver-1.0.js      oldfile1-ver-2.0.js  
oldfile2-ver-1.0.js      oldfile2-ver-2.0.js  
oldfile3-ver-1.0.js      oldfile3-ver-2.0.js  
oldfile4-ver-1.0.js      oldfile4-ver-2.0.js  

The script should change all the oldfile1-ver-1.0.js into oldfile1-ver-2.0.js in the html, php files

I would run this script before i start uploading.

Finally the script could create a list of files and line number where it made the update.

The solution can be in PERL/PHP/BATCH or anything thats nice and elegant

link|improve this question
feedback

2 Answers

MODIFY FILE CONTENTS:

find -type f -exec sed 's/ver-1.0/ver-2.0/g' -i {} \;

MODIFY FILE NAMES:

This would rename recursively on linux:

find -exec rename 's/ver-1.0/ver-2.0/' {} \;

On windows you can install cygwin and i think the syntax would be:

find -exec rename ver-1.0 ver-2.0 {} \;
link|improve this answer
feedback

What LatidSuD has handles the physical files themselves, but you probably want something like sed, or perl to handle the html references. Something like this should work:

perl -pi -e 's|ver-1\.0\.js|ver-2.0.js|g' *.html

This assumes you're only changing the version tag. If you're changing other parts, just correct the replace statement as necessary. To get fancy, you could include it as a bash script, and feed in the values, like this (named fix_references.sh for example):

#!/bin/sh
perl -pi -e "s|$2|$3|g" $1

Then you simply call it like this:

./fix_references.sh filenametofix.php oldfile1-ver-1.0.js oldfile1-ver-2.0.js

Hope that gives you an idea.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.