0

Is this code enough to preload images on my website? I use Django template langue for the loop, instead of javascript, like there. Is there any advantage of using javascript? Is my way as good as the javascript way?

{% for marker in markers %}
    <img src="{{ marker.image }}" style="display: none"/>
{% endfor %}
Vítek Peterka
  • 89
  • 1
  • 2
  • 10
  • 1
    That won't "preload" anything - although I'm not sure I really understand that term. A Django template just gets converted on the server side to a regular HTML document, and sent to the browser. That snippet won't do anything different in the browser from just hardcoding all your images in an html document. – Robin Zigmond Sep 20 '18 at 18:09
  • @RobinZigmond when I hardcode all my images without showing them, they will load from the cache once I show them, right? Or am I missing something? – Vítek Peterka Sep 20 '18 at 18:13
  • I'm really not sure. Its possible the browser doesn't even fetch them until they need to be displayed. I don't think there's anything in the HTML or CSS specs which specifies how browsers should handle this - but this isn't something I have knowledge about. – Robin Zigmond Sep 20 '18 at 18:18
  • 1
    The server side (django) responds with an html page, not the static content (images, js, css), which is requested once the page loads int the _client_ (browser), that's why you can have static content in multiple servers. Note that the link you posted is _javascript_. You should ask the same question with js and css tags, which are the _client_ languages that can perform this. – schrodingerscatcuriosity Sep 20 '18 at 18:34

0 Answers0