loadResources()

Load resources dynamically one time.

loadResources() β€” Sniper Resource Loader

SniperJs can automatically load CSS and JavaScript from a configuration file named:

sniper.config.json

πŸ“„ Config File Structure


⭐ How Auto Loading Works

  • If autoLoad is not false (default = true) β†’ all keyless resources are loaded automatically.

  • Keyless = resources placed directly in:

    • "css": [...]

    • "scripts": "main.js"

    • "scripts": ["main.js"]

Example of keyless:

or


πŸ”§ Usage Patterns

1. Load resources by a single key

This will run all the resources specified under home

2. Load resources by multiple keys

This will run all the resources specified under home and dashabord

3. Load ALL keyed resources

This will run all the resources without a key. However, autoload is already doing this automatically, so this will not be necessary except the autoLoad is set to false.


4: Conditional loading


✨ Notes

  • Designed for simplicity and flexibility β€” beginners can use it immediately.

  • Supports:

    • async, defer, type, id, ... etc, position

    • objects, arrays, keyless scripts, CSS

  • Automatically resolves relative paths.

Last updated