Pages

Showing posts with label useful-conventions. Show all posts
Showing posts with label useful-conventions. Show all posts

Thursday, June 20, 2013

How to stop some images loading from chache

In some cases we need to stop loading resources from cache. Say for an example, when we need to update a profile picture, we should not allow the cache to load the image again. So how are we going to do this. You can achieve this in two different ways.

  1. Add a parameter to the end of the url. Eg: http://your.site.com?random=98798987987 Important thing to notice here is you need to add a random variable in order to make the url different from the previous one
  2. The other method is to configure the headers in the request . But the downside of this approach is, You will need to set different headers parameters based on different browsers. eg. header("Pragma-directive: no-cache"); header("Cache-directive: no-cache"); header("Cache-control: no-cache"); header("Pragma: no-cache");  header("Expires: 0")

Friday, May 24, 2013

how to store user uploaded files in a web app

Generally for simple apps you can use a hash as the file name and link the file using a database. Another approach would be to keep the file in the database. But that would mean the database would fill up quite quickly and it'll cause high usage of db as well. Then again another simple approach is to transfer it to a hosting service and then provide the URL in order to retrieve it. However there are things that needs to be addressed like the file size, number of files, load etc... Therefore the best way is to make sure that the method you implement, suits your requirements. I came across this nice article on how facebook provide the infrastructure to store photos. This provide some insight into how large scale services are organized in order to provide the fascility.