0
0
Ruby on Railsframework~20 mins

Import maps (Rails 7+) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Import Maps Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when you add a new JavaScript package to importmap.rb but forget to pin it?

In a Rails 7 app using import maps, you add a new JavaScript package to config/importmap.rb but do not pin it. What will happen when you try to use it in your JavaScript code?

Ruby on Rails
import { example } from 'new-package'
example()
AThe browser will throw a 404 error because the package is not mapped and cannot be found.
BRails will automatically pin the package at runtime, so it works without errors.
CThe package will load from the CDN by default without any configuration needed.
DThe JavaScript will silently fail without any error or warning.
Attempts:
2 left
💡 Hint

Think about how import maps tell the browser where to find packages.

📝 Syntax
intermediate
2:00remaining
Which importmap.rb pin syntax is correct for pinning a package from a CDN?

Choose the correct way to pin the lodash package from a CDN in config/importmap.rb.

Apin "lodash", to: "https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"
Bpin lodash, url: "https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"
Cpin 'lodash' => 'https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js'
Dpin lodash, to: 'https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js'
Attempts:
2 left
💡 Hint

Look for the correct method signature and keyword arguments.

🔧 Debug
advanced
2:00remaining
Why does this importmap fail to load the local JavaScript file?

Given this config/importmap.rb snippet, why does the browser fail to load custom.js?

Ruby on Rails
pin "custom", to: "app/javascript/custom.js"
AThe path should be relative to <code>app/assets/javascripts</code>, not <code>app/javascript</code>.
BThe path should start with a slash: "/app/javascript/custom.js".
CLocal files must be placed in <code>app/assets/builds</code> and referenced from there.
DThe path should be relative to <code>app/javascript</code> without the folder name, just "custom.js".
Attempts:
2 left
💡 Hint

Think about how import maps resolve local files relative to the JavaScript root.

state_output
advanced
2:00remaining
What is the effect of running bin/importmap json in a Rails 7 app?

After pinning packages in config/importmap.rb, you run bin/importmap json. What does this command do?

AIt compiles all JavaScript files into a single bundle for faster loading.
BIt outputs the current import map as a JSON object showing all pinned packages and their URLs.
CIt clears all pinned packages from the import map.
DIt updates the <code>importmap.rb</code> file with new pins from the CDN automatically.
Attempts:
2 left
💡 Hint

Consider what a JSON output of an import map would represent.

🧠 Conceptual
expert
3:00remaining
Why might you choose import maps over bundlers like Webpack in Rails 7?

Which of the following is the strongest reason to prefer import maps instead of bundlers like Webpack in a Rails 7 project?

AImport maps support all modern JavaScript features without any browser compatibility issues.
BImport maps automatically optimize and minify JavaScript for production better than bundlers.
CImport maps allow you to manage JavaScript dependencies without a build step, simplifying setup and deployment.
DImport maps enable server-side rendering of JavaScript components by default.
Attempts:
2 left
💡 Hint

Think about what bundlers require compared to import maps.