Forum Discussion
Yes it works, but that wasn't the problem.
Thanks for your suggestions anyway.
Great question. We did this with Browserify Shim.
You'd do something like this in your package.json:
"browserify-shim": {
"jQuery": "global:LITHIUM.jQuery"
}
Then in your bundle you can import Lithium's jQuery
const $ = require('jQuery')
More info here: https://github.com/thlorenz/browserify-shim
OR...
A less elegant way might be something like:
var $ = window.LITHIUM.jQuery || {};
You'd want to put your script includes in last_chance_html to ensure the Lithium object has loaded by the time your files load and make the assignment. I wouldn't recommend this, but it might work as a quick solution.
- snaffle7 years agoExpert
Thanks ttadej that's exactly the kind of information we were looking for.
We actually have a mutiple skin set up that each have different JS includes so the first option is the one we'll look in to as we'd rather not dump them all in to last_chance_html and have them all loading when they don't need to.
- marco557 years agoGenius
If I'm understanding what you're going for, another option might be to include the asset through js with $(document).ready(), it should load after jquery.
<@liaAddScript> ; //optional js $(document).ready( function () { var my_script = document.createElement("script"); my_script.setAttribute("src","[asset_path]"); my_script.setAttribute( "type", "text/javascript" ); document.head.appendChild(my_script); } ); })(LITHIUM.jQuery); </@liaAddScript>
- marco557 years agoGenius
Yikes, sorry, I posted the syntax wrong...corrected:
<@liaAddScript> ;(function($) { //optional js $(document).ready( function () { var my_script = document.createElement("script"); my_script.setAttribute("src","[asset_path]"); my_script.setAttribute( "type", "text/javascript" ); document.head.appendChild(my_script); } ); })(LITHIUM.jQuery);
</@liaAddScript>
Related Content
- 14 years ago
- 12 years ago
- 11 years ago