2

I have been thinking what could be the fastest way to show base64/img data to the user, i could generate the data when the user is registered and then store it to database, or generate it every time it is requested.

this is something i am thinking to make the response fast and i could just generate the img data in client. which many elements will have them generated, but i don't know if this could make the loading data take longer time.

So, is it better to store base64/img generated data on database?.. if not then who should generate them.. client or server?

update: To be more clear on the question, the generated data is Identicon, my concern is what would be the fastest way to show it to user, this could be shown once or multiple times in a single view regardless the power on server

1
  • 3
    which'd be preferable depends in part at least on the size of the data and the time needed to generate it.
    – jwenting
    Jul 14, 2015 at 7:17

3 Answers 3

1

... i could generate the data when the user is registered and then store it to database, or generate it every time it is requested.

This sounds like two completely different operations to me:

1) Generate [static] "image" data when the user registers and store it in a database.

2) Generate some dynamic "image" data whenever the user visits a page.

My question is this: Having loaded your "image" data into a database, what are you going to do with it? If the answer is simply ...

Read it back, write it to a file and display it in the user's browser

... then you're better off leaving the "image" in the file system, from where it can be served directly.

Even if you're adding some sort of dynamic content to the "image", then storing or, at least, cacheing it in the file system will still make for a quicker, operation overall.

Trying to do anything "client-side" is risky. Even putting aside the vaguaries of browser implementations of JavaScript (at least until WASM https://en.wikipedia.org/wiki/WebAssembly takes off), you're totally reliant on the available processing power of the client machine to handle all that "image" processing you want to do. That might be OK on somebody's shiny, new multi-GHz Uber-phone but on their clunky, old, 10-year-old laptop? Perhaps not so much.

1
  • well, if i am going to store the data to database, i would just read it and send it to client, so client-side will just render it, and i was really thinking about doing that way, i suppose it would take less resource to read data already generated than generate it with a hash value all the time it is being requested and it would be sightly faster, i could also store it into a temp file, i will keep that in mind, thanks Jul 14, 2015 at 20:03
1

I would say the easiest way is to store it physically : you don't need any kind of handler or database call to retrieve the image, further managing will most probably be easier aswell as client-cache handling.

There's actually not a lot of good reasons to clutter your database with images, so I would say this alternative is only just acceptable in some specific cases like needing this image distributed among several servers. And even then, you could think about something like a CDN to share physically stored images accross multiple servers.

In some cases, you could also think about BASE64 encoded images in the CSS file, which may open the doors to responsiveness and have an impact on loading time by reducing the number of requests, with an impact on CSS file size though.

So, long story short: unless very specific requirements, the best is to store it in a (distributed) filesystem.

3
  • well, let's assume this data is generated from identicon, the application i am developing will just contact the server through Restful API, should i store text generated data in database along with the related user? or generate the data everytime it is requested, if it's better generating it for every request, should client or server generate it for faster data transfering or perfomance Jul 14, 2015 at 7:24
  • I guess if it is an identicon, you will display it to other users, not only the one logged in. There is possibly quite a big number of hits on that file, and although you will already be requesting database, it will also increase the amount of data transfered from it to the webserver, which might become quite big in the case of a page listing users for example. Now, I must admit the best solution heavily depends on your specific requirements, which as stated by LMSingh in his answer are not 100% clear right now. You might want to be more specific in your question...
    – Laurent S.
    Jul 14, 2015 at 7:46
  • i have updated my question to be more clear Jul 14, 2015 at 7:55
0

Nosthertus, please clarify your question more. I'll answer based on what I can understand now but will change/update it once you clarify.

If you generate once and read many times, then storing is a good idea.

Storing directly in the database is a bit more programming but has the benefits of putting everything in logically a single view that any app can use. Storing in a filesystem is not advisable because you don't get some of the DB beneits (depending on your choice of database platform) like transaction handling etc.

However what little I know about identicons is that depending upon what you're doing, the identicon for any use could be different if they moved to another machine or IP address. So in that case you have to generate every time.

Your follow on question about "is it better to generate on client or server"... This is important in that can you safely guarantee that if generated on client or server, the resulting image will be identical? That depends on what algorith you're using.

So clarifications needed are.. instead of vague "let's assume", can you clearly state what you're trying to do? What are you concerns? Performance or space usage? How does this image get used in the UI?

1
  • i apologize for not being totally clear on the question and i will make the changes on the question, for what you have told me about the algorithm used to generate the image, i think this would be better on the server. but still my concern is the time it takes to response client regardless the speed bandwitch Jul 14, 2015 at 7:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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