Comments (10)
Second, as far as printing scripts inline is concerned, we mainly need that to create a global JS object. See: https://github.com/gocodebox/lifterlms/blob/master/includes/class.llms.frontend.assets.php#L189-L201 and https://github.com/gocodebox/lifterlms/blob/master/includes/class.llms.frontend.assets.php#L96-L100
So, we could do exactly what WordPress core does, i.e., print this global object in the header or create a new js file and load this as the first file in the footer.
In tandem, every other script we register would always have this as a dependency, thereby ensuring that the object is always available when any of the scripts need it.
from lifterlms.
@scottwyden this is helpful but isn't usable code I can integrate into the codebase as it's not a real fix, just a patch.
The ideal solution we need here is to rewrite the actual enqueue scripts or methods so that things are only enqueued when they need to be...
Thanks for your effort here and if you're willing, please look at https://github.com/gocodebox/lifterlms/blob/master/includes/class.llms.frontend.assets.php where the assets are originally enqueued.
I'll leave the issue open and get it resolved as per my note in the topic at wordpress.org but I can't use this script in the codebase, sorry!
from lifterlms.
I'm not a coder otherwise I'd totally help.
from lifterlms.
@scottwyden I completely understand. We'll leave this open until we get a chance to rework it internally then.
Take care,
from lifterlms.
Sounds great :-)
from lifterlms.
I'm not going to rewrite your code for you,
...misses point of community / open source :where's-the-homer-doh-emoji-when-I-need-it:
but I'll make an attempt and try to keep my Texas Sized thoughts to myself
a simple fork and a merge wouldn't have hurt @scottwyden 😎 Hell, 'ya already did the (great) work 👍
Ok, pardon me b/c I'm in video editing mode right now and the only thing rattlin' through my puny medulla oblongata is my wife pointing out how many ums
I used..... but: I'd rather contribute anything always, than something great never! ~ha!
Shouldn't (something like) this
if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
wpcf7_enqueue_scripts();
}
(replacing CF7 w/ lifterlms
of course)
be placed somewhere around line 55 of class.llms.frontend.assets.php
so that it wraps up this: https://github.com/gocodebox/lifterlms/blob/master/includes/class.llms.frontend.assets.php#L55-L74
Likewise, something like this here:
if ( function_exists( 'wpcf7_enqueue_styles' ) ) {
wpcf7_enqueue_styles();
}
would be somewhere yonder near line 33 of class.llms.frontend.assets.php
so that it takes care of this:
https://github.com/gocodebox/lifterlms/blob/master/includes/class.llms.frontend.assets.php#L55-L74
#NotAfraidToBeWrong #AlwaysBeLearning
from lifterlms.
This seems to be the next logical step in script loading and optimisation after #484.
from lifterlms.
Will refactor some of the enqueuing mechanisms alongside #562.
from lifterlms.
Thinking aloud. Do let me know if I am missing something here (esp @thomasplevy):
There are only three situations when LifterLMS related scripts need to be loaded:
- When we are on specific LifterLMS course element.
- When we are on a page that uses a specific LifterLMS shortcode.
- When we are on a page that uses a LifterLMS related sidebar widget.
I'll dig into more specifics of exactly what script is needed for each such scenario and specific sub-scenarios.
For shortcodes, I considered using has_shortcode but that has a performance issue. However, if the asset (script or style) is registered separately but only enqueued inside the shortcode's output function, it will only get enqueued on the page where the shortcode is actually used. I looked for some confirmation and found one here: https://gist.github.com/mathetos/c665f24cd7d8d8a1fbad63a8d5c9a741#file-better_shortcode-php & https://www.thewpcrowd.com/wordpress/enqueuing-scripts-only-when-widget-or-shortcode/
In a similar way, widget related scripts can be loaded only on pages that contain the widget. See: https://wordpress.stackexchange.com/a/48346/20375
However, this means that we'd need to refactor asset enqueuing from the current mechanism. In https://github.com/gocodebox/lifterlms/blob/master/includes/class.llms.frontend.assets.php, we only register all scripts and move the actual enqueuing inside each individual module
. Or better still, move all asset management within the module that needs such an asset.
This also works towards the goal of having self-contained modules that can just hooked and unhooked from the main plugin in a plugins-within-a-plugin kind of architecture.
With the way wp_enqueue_script()
and related work, duplication isn't an issue since in the end only one copy is going to be enqueued on one application state.
from lifterlms.
While going through the documentation I stumbled upon this:
https://developer.lifterlms.com/reference/classes/llms_frontend_assets/enqueue_scripts/
The first lines say:
// I don't think we need these next 3 scripts.
wp_enqueue_script( 'jquery-ui-tooltip' );
wp_enqueue_script( 'jquery-ui-datepicker' );
wp_enqueue_script( 'jquery-ui-slider' );
llms()->assets->enqueue_script( 'webui-popover' );
My guess is the first optimization thing you could do is remove jquery-ui, and if something from it is needed, then write it in your own js file, reduces requests.
from lifterlms.
Related Issues (20)
- Dashboard Widget visible on the WordPress dashboard main page to any role
- Date that the user started and completed the course HOT 1
- Bundle Add-ons & More Banners/Author Images in Core LifterLMS
- Find a way to invalidate the object cache for LifterLMS Reports.
- Cloned Courses Enrollment and Open Message Shortcodes Are Not Replacing Origin Info ID with new info ID HOT 3
- Inconsistent behavior with Auto Saving while using Course Builder. HOT 6
- Membership restriction on page only shows the first membership HOT 1
- Object Caching breaks the Course Builder and Default Lesson Blocks. HOT 2
- Strings in libraries/lifterlms-blocks/assets/js/llms-blocks.js do not translate. HOT 2
- The Access Plan Button Settings > Access Plan of the Access Plan Button Block can only display a maximum of 10 plans, HOT 3
- "Chaiyaphum" province (located in central northeastern Thailand) is missing from Thailand Province List.
- Allow private VideoPress videos to play when the URL is pasted on Video Embed URL. HOT 2
- Checkout redirect does not work when payments are made via PayPal. HOT 1
- The defined function name is different from the name in `function_exists`.
- Remove references to Quiz's property `random_answers`
- When the Topic is set to "Enrollment created" in WordPress Dashboard > LifterLMS > Settings > REST API > Webhooks, the payload only contains information on 1 course (even though there are more than one enrollments that occurred). HOT 1
- Clear class from LifterLMS admin CSS is breaking the admin pages of third-party plugins (JetPack CRM, HappyFiles Pro).
- Add a null check to prevent "Attempt to read property ... on null" PHP warnings. HOT 1
- Unexpected error when creating lessons without parent course. HOT 1
- Make long landscape images withing quiz questions fit the available width of the container.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lifterlms.