📖 Scenario: You are managing a website hosted on Firebase Hosting. To improve the loading speed of your web app, you want to preload a JavaScript bundle file so that the browser fetches it early.
🎯 Goal: Configure Firebase Hosting to preload a JavaScript bundle file named bundle.js by adding the correct HTTP header in the firebase.json configuration file.
📋 What You'll Learn
Create a firebase.json file with hosting configuration
Add a headers section to preload /bundle.js
Set the Link header with </bundle.js>; rel=preload; as=script
Ensure the configuration is valid and deployable
💡 Why This Matters
🌍 Real World
Preloading bundles helps websites load faster by telling browsers to fetch important files early, improving user experience.
💼 Career
Cloud engineers and web developers often configure hosting services like Firebase to optimize asset delivery and site speed.
Progress0 / 4 steps
1
Create the basic Firebase Hosting configuration
Create a firebase.json file with a hosting section that has a public directory set to public.
Firebase
Hint
The firebase.json file must have a hosting object with a public key set to "public".
2
Add headers configuration for bundle.js
Inside the hosting section, add a headers array with one object that has source set to /bundle.js.
Firebase
Hint
The headers array must contain an object with the source key exactly set to "/bundle.js".
3
Add the Link header to preload the bundle
Inside the object in the headers array, add a headers array with one object that sets key to Link and value to </bundle.js>; rel=preload; as=script.
Firebase
Hint
The headers array inside the source object must have an object with key "Link" and the correct value to preload the script.
4
Complete and validate the firebase.json configuration
Ensure the firebase.json file is a valid JSON object with the hosting section containing public and headers configured to preload /bundle.js with the correct Link header.
Firebase
Hint
Make sure the JSON is valid and all required keys and values are present exactly as specified.
Practice
(1/5)
1. What is the main purpose of bundle preloading in Firebase Hosting?
easy
A. To download important code bundles early for faster app loading
B. To increase the size of the app bundle for better caching
C. To delay loading of all code until user interaction
D. To disable code splitting in the app
Solution
Step 1: Understand bundle preloading concept
Bundle preloading downloads code bundles early before they are needed to speed up app loading.
Step 2: Identify the main benefit
This early download improves user experience by reducing wait time when features are accessed.
Final Answer:
To download important code bundles early for faster app loading -> Option A
Quick Check:
Bundle preloading = early download for speed [OK]
Hint: Preloading means downloading code before it's needed [OK]
Common Mistakes:
Thinking preloading delays code loading
Confusing preloading with disabling code splitting
Assuming preloading increases bundle size
2. Which is the correct way to configure bundle preloading in firebase.json under hosting?
easy
A. "preloadBundles": {"bundle1.js": true, "bundle2.js": true}
B. "preloadBundles": "bundle1.js, bundle2.js"
C. "preloadBundles": ["bundle1.js", "bundle2.js"]
D. "preloadBundles": [bundle1.js, bundle2.js]
Solution
Step 1: Review JSON array syntax for preloadBundles
The correct syntax uses an array of strings listing bundle filenames.
Step 2: Identify correct JSON format
"preloadBundles": ["bundle1.js", "bundle2.js"] correctly uses an array of quoted strings, which is valid JSON.
Final Answer:
"preloadBundles": ["bundle1.js", "bundle2.js"] -> Option C
Quick Check:
Preload bundles = array of strings [OK]
Hint: Use array of quoted strings for bundle names in JSON [OK]
Common Mistakes:
Using unquoted bundle names causing syntax errors
Passing bundles as a single string instead of array
B. Using preloadBundles inside hosting is not supported
C. Bundles must be objects, not strings
D. Missing quotes around 'app2.js' causes JSON syntax error
Solution
Step 1: Check JSON syntax for bundle names
All bundle names must be strings enclosed in double quotes.
Step 2: Identify error in given config
'app2.js' is missing quotes, causing invalid JSON syntax.
Final Answer:
Missing quotes around 'app2.js' causes JSON syntax error -> Option D
Quick Check:
JSON strings need quotes [OK]
Hint: Always quote bundle names as strings in JSON [OK]
Common Mistakes:
Forgetting quotes around bundle names
Placing preloadBundles outside hosting
Using objects instead of string arrays
5. You want to preload bundles only for features users often visit first, but not preload large rarely used bundles. How should you configure firebase.json to optimize loading?
hard
A. List only frequently used bundles in preloadBundles to download early
B. Preload all bundles regardless of usage to avoid delays
C. Do not use preloadBundles; load all bundles on demand
D. Preload only the largest bundles to improve caching
Solution
Step 1: Understand preload strategy
Preloading bundles that users access often improves perceived speed without wasting bandwidth.
Step 2: Apply selective preloading
Only list frequently used bundles in preloadBundles to optimize loading and avoid unnecessary downloads.
Final Answer:
List only frequently used bundles in preloadBundles to download early -> Option A
Quick Check:
Preload important bundles only for best performance [OK]
Hint: Preload only bundles users need early to save bandwidth [OK]
Common Mistakes:
Preloading all bundles causing slow initial load
Ignoring usage patterns when preloading
Preloading large unused bundles wasting resources
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.