If the barcode is generated based on unique number of the entity, should we store the barcode image in database ? Or should we use javascript libraries to draw barcode whenever necessary?
-
3The second option sounds much better. – Jose Manuel Abarca Rodríguez Jun 10 '15 at 20:29
-
1It depends. What are you optimizing for? – Matt Ball Jun 10 '15 at 20:29
-
Please take a look at this [answer](http://stackoverflow.com/a/3751/4270737) – Slico Jun 10 '15 at 20:31
2 Answers
If you can generate the barcode on the fly then I would advise storing the code rather then an image.
My reasoning for this is as follows:
You will take up less space in the server's database.
You will use less internet bandwidth by serving a simple number verses an image.
Even if you reduce the image colour palette to monochrome and compress the image. A primitive type (i.e. strings,integers...) will take fewer bytes than an image.
The code for storing a number will be a lot less complex than storing an image.
Operations can be performed on numbers later. For example you could use the data for processing. If you need to change the IDs then the operation will be a lot simpler than regenerating all of the images in your database. You could also do more complex queries in the future with that number and you could use it to tie information together in a relational database.

- 3,013
- 2
- 34
- 52
-
1Agree. And it takes no server resources to draw the image each time as that task is offloaded to the client machine. Under normal conditions I can't think of a reason to store the images. – Yogi Jun 10 '15 at 20:37
-
2Adding to that. if/when the barcode design/output needs changing. You don't have to refresh and entire database worth of values. – castis Jun 10 '15 at 20:38
-
Store barcode image is not necessary and will full your database with data that will be obsolet soon and will be stored for ever. in addition, barcode is not requested every time user request the page. and also don't consume a lot of cpu to be drawn. So, it's best you save just the number and just if user request, you draw the image. this way. you'll keep your database light.

- 184
- 13