D
D
Dmitry Filandor2015-07-01 13:42:34
ASP.NET
Dmitry Filandor, 2015-07-01 13:42:34

Is the widget display algorithm correct?

Hello! There is a site of aphorisms, I want to make a service: users generate code, paste it on their site in the right place (sidebar) and one or another aphorism is displayed there.
Here's what I did:
Once a day, 10 pictures with printed text of aphorisms are generated (randomly) in a certain folder.
Here's how I think to implement it further:
The GetRandomCard action returns a view with one of the 10 pictures (that were previously generated). The action is cached for 1 hour, so the user on his site will update the aphorism once an hour. The code is a regular frame with an action.
Specialists in js will say that this is a script (display on any site in which the script is inserted one of 10 pictures from a remote folder (on the site of aphorisms)) I did it twice, but I’m not strong in scripts, therefore it is.
I will be glad for advice.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
D', 2015-07-01
@LifeAct

You don't need any JS
Just a map <_img src="path_to_site/getrandomimage"/>
Where getrandomimage - gives a random image from the server.
> although I need more than a picture, I also need a design and a link to the source site
Well, give the client html:

<div>
<a href="http://site"><img src="http://site/rndimage" /></a>
</div>

A
Alexey Ukolov, 2015-07-01
@alexey-m-ukolov

A big advantage of using js is that the client site does not wait until the image is loaded from your server, which may even die.
I would make a widget that would give to customers via <script src="site.com/widget.js" async></script>, and inside the widget I would already generate the address of the picture and insert it in the right place. But if the level of knowledge of js is insufficient, then this, of course, is overkill.

R
Roman Mirilaczvili, 2015-07-01
@2ord

I prefer the answer of Alexey Ukolov
As an option for securing against server unavailability (and this often happens in life), use a CDN service to serve a JS widget, such as CloudFlare. The widget can specify parameters for generating images and other content.

<script src="cdn.site.com/widget.js" async></script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question