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.
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 93 94 |
# File 'lib/rhales/configuration.rb', line 63 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
58 59 60 |
# File 'lib/rhales/configuration.rb', line 58 def api_cache_enabled @api_cache_enabled end |
#api_cache_ttl ⇒ Object
Caching configuration for API endpoints
58 59 60 |
# File 'lib/rhales/configuration.rb', line 58 def api_cache_ttl @api_cache_ttl end |
#api_endpoint_enabled ⇒ Object
API endpoint configuration for link-based strategies
43 44 45 |
# File 'lib/rhales/configuration.rb', line 43 def api_endpoint_enabled @api_endpoint_enabled end |
#api_endpoint_path ⇒ Object
API endpoint configuration for link-based strategies
43 44 45 |
# File 'lib/rhales/configuration.rb', line 43 def api_endpoint_path @api_endpoint_path end |
#cors_enabled ⇒ Object
CORS configuration for API endpoints
61 62 63 |
# File 'lib/rhales/configuration.rb', line 61 def cors_enabled @cors_enabled end |
#cors_origin ⇒ Object
CORS configuration for API endpoints
61 62 63 |
# File 'lib/rhales/configuration.rb', line 61 def cors_origin @cors_origin end |
#disable_early_for_templates ⇒ Object
Disable early injection for specific templates (array of template names)
40 41 42 |
# File 'lib/rhales/configuration.rb', line 40 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
34 35 36 |
# File 'lib/rhales/configuration.rb', line 34 def fallback_to_late @fallback_to_late end |
#fallback_when_unsafe ⇒ Object
Whether to fallback to late injection when early injection is unsafe
37 38 39 |
# File 'lib/rhales/configuration.rb', line 37 def fallback_when_unsafe @fallback_when_unsafe end |
#injection_strategy ⇒ Object
Injection strategy - one of VALID_STRATEGIES
28 29 30 |
# File 'lib/rhales/configuration.rb', line 28 def injection_strategy @injection_strategy end |
#lazy_mount_selector ⇒ Object
Lazy loading configuration
52 53 54 |
# File 'lib/rhales/configuration.rb', line 52 def lazy_mount_selector @lazy_mount_selector end |
#link_crossorigin ⇒ Object
Link tag configuration
46 47 48 |
# File 'lib/rhales/configuration.rb', line 46 def link_crossorigin @link_crossorigin end |
#module_export_enabled ⇒ Object
Module export configuration for :modulepreload strategy
49 50 51 |
# File 'lib/rhales/configuration.rb', line 49 def module_export_enabled @module_export_enabled end |
#mount_point_selectors ⇒ Object
Array of CSS selectors to detect frontend mount points
31 32 33 |
# File 'lib/rhales/configuration.rb', line 31 def mount_point_selectors @mount_point_selectors end |
#reflection_enabled ⇒ Object
Data attribute reflection system
55 56 57 |
# File 'lib/rhales/configuration.rb', line 55 def reflection_enabled @reflection_enabled end |
Instance Method Details
#api_endpoints_required? ⇒ Boolean
Check if API endpoints should be enabled
110 111 112 |
# File 'lib/rhales/configuration.rb', line 110 def api_endpoints_required? link_based_strategy? || @api_endpoint_enabled end |
#link_based_strategy? ⇒ Boolean
Check if current strategy is link-based
105 106 107 |
# File 'lib/rhales/configuration.rb', line 105 def link_based_strategy? LINK_BASED_STRATEGIES.include?(@injection_strategy) end |