CSS not updating on local python httpserver restart

Slater Victoroff picture Slater Victoroff · Feb 23, 2013 · Viewed 8.2k times · Source

I'm fairly new to the world of web dev and http servers and the like, but I have a basic shell script as follows:

PORT=2600 
if [[ $1 =~ ^[0-9]+$ ]]
  then PORT=$1
fi

echo "Starting local http server (ctrl-c to exit)"
echo ""
echo "  Demo:   http://127.0.0.1:$PORT/demo"
echo ""
python -m SimpleHTTPServer $PORT

It seems to work alright for just putting things up, but when I update the css file in my demo, it rarely and inconsistently will update the css displayed on the page. The changes to any html it renders fine, and it has occasionally shown the css changes, but I feel like I'm doing something fundamentally wrong here. Thoughts?

Answer

Brad picture Brad · Feb 23, 2013

The issue is browser caching. You can a) clear browser cache or turn on incognito browsing or b) append some sort of cache busting to your css/js resources ie foo.css?(timestamp) or foo.css?(version#) etc. For larger systems, the latter is better so that you don't force users to clear browser cache after a code push to production.