9

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?

Slater Victoroff
  • 19,762
  • 18
  • 78
  • 135
  • i know this is a bit of a no-brainer but do you have a serverside cache? are you clearing client side cache? if your css files aren't versioned ie foo.css?(timestamp) etc, then the browser is likely to cache it for a period of time. – Brad Feb 23 '13 at 18:18
  • Is there a way to force clearing of the cache? – Slater Victoroff Feb 23 '13 at 18:21
  • yep. depends on the browser but for firefox for example you can ctrl+shift+del and you'll get an pop up to clear the cache. Furthermore, you can choose to browse discreetly in chrome to prevent caching of any kind. That said, a better practice is to append a version number or timestamp to the end of the file so the browser thinks its a new file and doesn't cache. – Brad Feb 23 '13 at 18:24
  • Oh, fantastic, using incog mode totally fixed this. Did not know about caches. Mind making it an answer so I can accept it? – Slater Victoroff Feb 23 '13 at 18:48

1 Answers1

17

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.

Brad
  • 5,430
  • 4
  • 28
  • 42