Class: Rhales::HydrationConfiguration
- Inherits:
-
Object
- Object
- Rhales::HydrationConfiguration
- Defined in:
- lib/rhales/configuration.rb
Overview
Hydration-specific configuration settings
Controls how hydration scripts are injected into HTML templates. Supports multiple injection strategies for different performance characteristics:
Traditional Strategies
:late
(default) - injects before </body> tag (safest, backwards compatible):early
- injects before detected mount points for improved performance:earliest
- injects in HTML head section for maximum performance
Link-Based Strategies (API endpoints)
:link
- basic link reference to API endpoint:prefetch
- browser prefetch for future page loads:preload
- high priority preload for current page:modulepreload
- ES module preloading:lazy
- intersection observer-based lazy loading
Constant Summary collapse
- VALID_STRATEGIES =
[:late, :early, :earliest, :link, :prefetch, :preload, :modulepreload, :lazy].freeze
- LINK_BASED_STRATEGIES =
[:link, :prefetch, :preload, :modulepreload, :lazy].freeze
- DEFAULT_API_CACHE_TTL =
5 minutes
300
Instance Attribute Summary collapse
-
#api_cache_enabled ⇒ Object
Caching configuration for API endpoints.
-
#api_cache_ttl ⇒ Object
Caching configuration for API endpoints.
-
#api_endpoint_enabled ⇒ Object
API endpoint configuration for link-based strategies.
-
#api_endpoint_path ⇒ Object
API endpoint configuration for link-based strategies.
-
#cors_enabled ⇒ Object
CORS configuration for API endpoints.
-
#cors_origin ⇒ Object
CORS configuration for API endpoints.
-
#disable_early_for_templates ⇒ Object
Disable early injection for specific templates (array of template names).
-
#fallback_to_late ⇒ Object
Whether to fallback to late injection when no mount points detected.
-
#fallback_when_unsafe ⇒ Object
Whether to fallback to late injection when early injection is unsafe.
-
#injection_strategy ⇒ Object
Injection strategy - one of VALID_STRATEGIES.
-
#lazy_mount_selector ⇒ Object
Lazy loading configuration.
-
#link_crossorigin ⇒ Object
Link tag configuration.
-
#module_export_enabled ⇒ Object
Module export configuration for :modulepreload strategy.
-
#mount_point_selectors ⇒ Object
Array of CSS selectors to detect frontend mount points.
-
#reflection_enabled ⇒ Object
Data attribute reflection system.
Instance Method Summary collapse
-
#api_endpoints_required? ⇒ Boolean
Check if API endpoints should be enabled.
-
#initialize ⇒ HydrationConfiguration
constructor
A new instance of HydrationConfiguration.
-
#link_based_strategy? ⇒ Boolean
Check if current strategy is link-based.
Constructor Details
#initialize ⇒ HydrationConfiguration
Returns a new instance of HydrationConfiguration.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rhales/configuration.rb', line 61 def initialize # Traditional strategy settings @injection_strategy = :late @mount_point_selectors = ['#app', '#root', '[data-rsfc-mount]', '[data-mount]'] @fallback_to_late = true @fallback_when_unsafe = true @disable_early_for_templates = [] # API endpoint settings @api_endpoint_enabled = false @api_endpoint_path = '/api/hydration' # Link tag settings @link_crossorigin = true # Module export settings @module_export_enabled = false # Lazy loading settings @lazy_mount_selector = '#app' # Reflection system settings @reflection_enabled = true # Caching settings @api_cache_enabled = false @api_cache_ttl = DEFAULT_API_CACHE_TTL # CORS settings @cors_enabled = false @cors_origin = '*' end |
Instance Attribute Details
#api_cache_enabled ⇒ Object
Caching configuration for API endpoints
56 57 58 |
# File 'lib/rhales/configuration.rb', line 56 def api_cache_enabled @api_cache_enabled end |
#api_cache_ttl ⇒ Object
Caching configuration for API endpoints
56 57 58 |
# File 'lib/rhales/configuration.rb', line 56 def api_cache_ttl @api_cache_ttl end |
#api_endpoint_enabled ⇒ Object
API endpoint configuration for link-based strategies
41 42 43 |
# File 'lib/rhales/configuration.rb', line 41 def api_endpoint_enabled @api_endpoint_enabled end |
#api_endpoint_path ⇒ Object
API endpoint configuration for link-based strategies
41 42 43 |
# File 'lib/rhales/configuration.rb', line 41 def api_endpoint_path @api_endpoint_path end |
#cors_enabled ⇒ Object
CORS configuration for API endpoints
59 60 61 |
# File 'lib/rhales/configuration.rb', line 59 def cors_enabled @cors_enabled end |
#cors_origin ⇒ Object
CORS configuration for API endpoints
59 60 61 |
# File 'lib/rhales/configuration.rb', line 59 def cors_origin @cors_origin end |
#disable_early_for_templates ⇒ Object
Disable early injection for specific templates (array of template names)
38 39 40 |
# File 'lib/rhales/configuration.rb', line 38 def disable_early_for_templates @disable_early_for_templates end |
#fallback_to_late ⇒ Object
Whether to fallback to late injection when no mount points detected
32 33 34 |
# File 'lib/rhales/configuration.rb', line 32 def fallback_to_late @fallback_to_late end |
#fallback_when_unsafe ⇒ Object
Whether to fallback to late injection when early injection is unsafe
35 36 37 |
# File 'lib/rhales/configuration.rb', line 35 def fallback_when_unsafe @fallback_when_unsafe end |
#injection_strategy ⇒ Object
Injection strategy - one of VALID_STRATEGIES
26 27 28 |
# File 'lib/rhales/configuration.rb', line 26 def injection_strategy @injection_strategy end |
#lazy_mount_selector ⇒ Object
Lazy loading configuration
50 51 52 |
# File 'lib/rhales/configuration.rb', line 50 def lazy_mount_selector @lazy_mount_selector end |
#link_crossorigin ⇒ Object
Link tag configuration
44 45 46 |
# File 'lib/rhales/configuration.rb', line 44 def link_crossorigin @link_crossorigin end |
#module_export_enabled ⇒ Object
Module export configuration for :modulepreload strategy
47 48 49 |
# File 'lib/rhales/configuration.rb', line 47 def module_export_enabled @module_export_enabled end |
#mount_point_selectors ⇒ Object
Array of CSS selectors to detect frontend mount points
29 30 31 |
# File 'lib/rhales/configuration.rb', line 29 def mount_point_selectors @mount_point_selectors end |
#reflection_enabled ⇒ Object
Data attribute reflection system
53 54 55 |
# File 'lib/rhales/configuration.rb', line 53 def reflection_enabled @reflection_enabled end |
Instance Method Details
#api_endpoints_required? ⇒ Boolean
Check if API endpoints should be enabled
108 109 110 |
# File 'lib/rhales/configuration.rb', line 108 def api_endpoints_required? link_based_strategy? || @api_endpoint_enabled end |
#link_based_strategy? ⇒ Boolean
Check if current strategy is link-based
103 104 105 |
# File 'lib/rhales/configuration.rb', line 103 def link_based_strategy? LINK_BASED_STRATEGIES.include?(@injection_strategy) end |