4 years ago

Best way to load javascript on a per page basis?

Posted 4 years ago by splaq

Basically I'm looking for a way to use a bit on javascript on one page while not on another.. This way (at least in a large scale application) you will be saving load times and bandwidth if you're not loading all of the site's javascript on the master template..

I would imagine you could include it in the templates but that wouldn't be semantically correct would it? Also what's the point of having a long @if/@elseif statement in your blade? Kind of seems like overkill to me.

Maybe including a variable in your route/controller that holds the link tag to the script you want to run and pass that through to the view with the rest of your data? That almost seems like the best way to do it or does it? What are your thoughts?

I may be putting this into practice but right now javascript in the application I'm working on is just a thought.. I may just keep it simple. But in principle this is a question and thought on best practices I suppose.

What are your theories and why?

Please sign in or create an account to participate in this conversation.