Block CSS/JS Not Loading
I have some custom blocks as part of a site. These blocks include custom CSS/JS files I want to include with each block so they are only loaded when required. The CSS/JS files are built using webpack and compiled to my theme directory and then I am loading them into the block via the blocks controller like so:
This seems to work 99% of the time but every now and then it will stop loading either one of both of the files on one block. Sometimes clearing the site cache fixes it, and sometimes it doesn't. This obviously isn't an ideal long terms solution as it means we have to keep on monitoring it closely and sometimes we just don't seem to be able to fix it.
I would really appreciate any advice on how we can resolve this. FYI we are using Concrete 8.5.4.
Could you tell us more. What happens when it doesn't load? Is it present in the page's markup? Is it throwing a 404 error? Anything you noticed?
What are your cache settings concerning JS and CSS?
Many thanks for your reply. When it doesn't load, there is no request to the CSS or JS file in the source code at all. Sometimes the CSS will load but not the JS, sometimes the JS but not the CSS and sometimes neither. It seems to be very random.
I have a handful of blocks all implementing the code and each one seems to experience the problem at different times.
I wish I could but unfortunately its not something I can share publicly.
I did some further digging on this yesterday and made an interesting discovery. I can see the approporate CSS or JS file being added to the raw HTML and there is a data attribute on it with a path to the file. However the actual src attribute is loading a cached file with a random string as the name and when I view that file, it is actually the file for a completely different module.
For some reason it seems to be loading assets from a different module. It is bizarre!
Any feedback would be greatly appreciated!
All the best
So make sure the file you're looking for is not there somewhere. If the data-src references more than one file (and it should) then the file loaded contains all of those files. Your file's code will be somewhere in it.