One the most amazing things about Discourse is that it is a Single Page Application. The page is loaded once and the content is swapped on demand - This is my understanding.
I was trying to integrate Masonry with Discourse and ran into a small problem.
I got Masonry to load great on first page load and everything works great:
However, if I navigate to another topic-list page or select a category then it does not work anymore and I get this:
The method I use to call Masonry is to add the script below to the </head>
<script>
$(".topic-list").imagesLoaded(function() {
    $(".topic-list").masonry({
      itemSelector: ".topic-list-item"
    });
  });
</script>
I understand why the issue occurs - I think. It occurs because the script is only loaded and fired on initial page load.
This means that the <head> element is not reloaded on every page load.
So, logically, my next step was to see if I can add the script somewhere where it will get run again when new content loads.
So I tried
</body><footer>
Without luck. For some reason the script never fires again after initial page load.
So, my question is how can I make sure this script runs on every page load? (for now… selective logic will come in later)
<script>
$(".topic-list").imagesLoaded(function() {
    $(".topic-list").masonry({
      itemSelector: ".topic-list-item"
    });
  });
</script>
            

) but I’m now glad I found an official example to lean back on.
 That’s the one!








