Reputation: 19
I have a PowerShell script that has gotten very big. To decrease load times, I would like to load only sections of the script that are currently being called.
Does dot sourcing a script still load it at runtime? Or does it wait until it hits that function before loading the other script?
Upvotes: 1
Views: 294
Reputation: 47802
It's hard to tell what the makeup of your current script is, but I would recommend just splitting your code into functions, possibly making a module out of it if appropriate.. When that script is initially parsed, it's only defining the functions and not executing them, so it will be very fast.
Dot sourcing takes the script you've specified and immediately executes it as though it had been at that spot in your original script.
Upvotes: 2