Reputation: 37377
Ok, so im trying to work out the fastest way of storing data on my page without slowing the page load:
The events anchors are created with a php loop, so i could create the data elements within this loop using either
or i could run the loop again, separately, this time inside script tags with jquery.data();
would really appreciate any thoughts on this!
Upvotes: 2
Views: 746
Reputation: 400932
A possibility would be to generate, on the server-side, a Javascript array or object that contains all the events, and inject it into the page as a Javascript variable.
Basically :
json_encode
Great thing with that solution it that is work for almost any possible kind of data, is quite fast, and quite easy to develop.
The generated HTML+JS code would look like this :
<script type="text/javascript">
var myArrayOfEvents = [ ... ];
</script>
And it could be generated with some PHP code like this :
<script type="text/javascript">
var myArrayOfEvents = <?php echo json_encode($myEvents); ?>;
</script>
Of course, up to you to :
Upvotes: 3