Module: RnStack::PerformanceHelper
- Defined in:
- app/helpers/rn_stack/performance_helper.rb
Instance Method Summary collapse
-
#optimized_script_tag(source, strategy: :async) ⇒ Object
Script loading strategy helper.
-
#self_hosted_font_tag(font_name, options = {}) ⇒ Object
Font optimization helper.
-
#with_isr_cache(key, expires_in: 1.hour, &block) ⇒ Object
ISR-like fragment caching: revalidates content periodically.
Instance Method Details
#optimized_script_tag(source, strategy: :async) ⇒ Object
Script loading strategy helper
15 16 17 18 19 20 21 22 23 24 |
# File 'app/helpers/rn_stack/performance_helper.rb', line 15 def optimized_script_tag(source, strategy: :async) case strategy when :async javascript_include_tag source, async: true when :defer javascript_include_tag source, defer: true else javascript_include_tag source end end |
#self_hosted_font_tag(font_name, options = {}) ⇒ Object
Font optimization helper
9 10 11 12 |
# File 'app/helpers/rn_stack/performance_helper.rb', line 9 def self_hosted_font_tag(font_name, = {}) # In Rails, fonts should be in app/assets/fonts tag.link(rel: "preload", href: asset_path("#{font_name}.woff2"), as: "font", type: "font/woff2", crossorigin: "anonymous") end |
#with_isr_cache(key, expires_in: 1.hour, &block) ⇒ Object
ISR-like fragment caching: revalidates content periodically
4 5 6 |
# File 'app/helpers/rn_stack/performance_helper.rb', line 4 def with_isr_cache(key, expires_in: 1.hour, &block) cache("isr/#{key}", expires_in: expires_in, &block) end |