Answer the question
In order to leave comments, you need to log in
Keep PHP logic or JavaScript?
I’m writing a teaser network and I’m a little tormented by doubts:
the advertising platform hosts a code like <script type="text/javascript" src="someurl.com/site_id/block_id"></script>
which, of course, loads the full JS code to generate a teaser block.
So I'm thinking - to pass the already rendered block to the client (logic in php), or give only the block data in, for example, JSON format, and render it using JS (logic in JS)?
Answer the question
In order to leave comments, you need to log in
For maximum loading speed, take all the rendering logic into a separate static JS script and compress it with gzip, and load the block data in JSON. Static JS will be cached and everything will fly :-) In addition, it will be possible to place several blocks on one page and process them all with the same JS, and not load them for each HTML.
It makes sense to transfer any tasks to the client side if it:
- saves server resources and/or speeds up page/data loading;
- does not complicate maintenance too much;
- does not compromise security (say, Javascript should not be used to check the correctness of filling out forms without duplication on the server side).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question