izi_lightup 1.0.7 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53eb89af799d0a5092528a4159f8f67f042e3ce4eb30903fba949e116857c924
4
- data.tar.gz: 9ae8a7f1c98d7b35fd4c31653f516845d190e3cd8d2642388765c44c5fee8e6f
3
+ metadata.gz: 21f41382e7ef7800607c021d33859c57b10a4408580acef3e068d92a2eaf6fdb
4
+ data.tar.gz: 635d22e277085980967845763882aaddfb8c3f161e4b0fff3bdb09d782f2a875
5
5
  SHA512:
6
- metadata.gz: 1a424b4f1b656fd599cdb0e73a8e30dd86116ae4bf73fba550fdafea3eae52e7460627bc8f014fd8d8fb7d2e94a39d2fd7ce6ffc5825cc308197ccbc41473040
7
- data.tar.gz: 80befcb20e4b325c8362a8da9f8b9b7f9d19573ea0cadc5e7d441f9a5b9c6ef59432b6e63ff0b435111bfe847343a320a279ad7a7d2db9b0850643e5d0894da0
6
+ metadata.gz: 3909f266b8eaf65aae1ee745bf6079508f31008181fe24083cdfeb914177886f0b03f3752457ee72c9871a40f1a6c41ed517f43a77f2e7e3d4d9e0fb6d3a54b8
7
+ data.tar.gz: 99964f117e4f1725b99375185891857310be36ecdaa119858f9b683297b85fd688eab1d97f6b8bc7c95811ca1bbec1ca74f60bf4ba5ade878b9f3d8e981ea9fb
@@ -1,6 +1,6 @@
1
1
  ((window, document) -> (
2
2
  EVENT_TYPE = window.__activeEventName || 'Activity'
3
- MAX_TIMEOUT = window.__activeTimeout || 5000
3
+ MAX_TIMEOUT = window.__activeTimeout || 10000
4
4
  TRACK_MARKING = window.__activeMark || '_real_track=true'
5
5
 
6
6
  if custom_mt = /^\?(\d+)$/.exec(window.location.search)
@@ -10,7 +10,7 @@
10
10
 
11
11
  while callbacks.length > 0
12
12
  callback = callbacks.shift()
13
- callback.call(window) if typeof(callback) is 'function'
13
+ callback.call(window, __required[id]) if typeof(callback) is 'function'
14
14
 
15
15
  _buildSubscriptions = (id, node) ->
16
16
  data = __required[id]
@@ -32,6 +32,7 @@
32
32
  data.callbacks.push(callback) if typeof(callback) is 'function'
33
33
 
34
34
  window.miniRequire ||= (key, source_url, callback = undefined) ->
35
+ key ||= Math.random().toString(36).slice(2, 12)
35
36
  id = "source_#{key.replace(/[^a-z0-9_\-]+/ig, '_')}"
36
37
  __required[id] ||= {loaded: false, callbacks: [], started: false}
37
38
 
@@ -50,9 +51,40 @@
50
51
  src.async = true
51
52
  src.defer = true
52
53
  src.src = source_url
54
+ __required[id].node = src
53
55
  _buildSubscriptions(id, src)
54
56
  _subscribe(id, callback)
55
57
 
56
58
  document.body.appendChild(src)
57
59
  true
60
+
61
+ window.miniPreload ||= (params, callback = undefined) ->
62
+ key = params.key || Math.random().toString(36).slice(2, 12)
63
+ callback ||= params.callback
64
+ source_url = params.src
65
+ id = "source_#{key.replace(/[^a-z0-9_\-]+/ig, '_')}"
66
+ __required[id] ||= {loaded: false, callbacks: [], started: false}
67
+
68
+ # subscribe only if no source
69
+ return _subscribe(id, callback) unless source_url?.length > 0
70
+
71
+ # subscribe only if already attached & started
72
+ return _subscribe(id, callback) if __required[id].started
73
+
74
+ # mark as started
75
+ __required[id].started = true
76
+
77
+ # attach script
78
+ src = document.createElement('link')
79
+ src.id = id
80
+ src.rel = 'preload'
81
+ src.href = source_url
82
+ src.as = params.as || 'style'
83
+ __required[id].node = src
84
+ _buildSubscriptions(id, src)
85
+ _subscribe(id, callback)
86
+
87
+ document.head.appendChild(src)
88
+ true
89
+
58
90
  ))(window, document)
@@ -28,7 +28,8 @@ module CriticalHelper
28
28
  end
29
29
 
30
30
  def critical_css(params = {})
31
- name = find_scoped_css('critical')
31
+ scope = params.fetch(:scope, 'critical')
32
+ name = find_scoped_css(scope)
32
33
  stylesheets = Array.wrap(params.fetch(:stylesheets, []))
33
34
  data = StringIO.new
34
35
 
@@ -70,6 +71,12 @@ module CriticalHelper
70
71
  end
71
72
 
72
73
  def asset_exist?(name)
73
- Rails.application.assets_manifest.find_sources(name)&.first&.present?
74
+ return manifest.find_sources(name)&.first&.present? if Rails.env.development?
75
+
76
+ manifest.assets.key?(name)
77
+ end
78
+
79
+ def manifest
80
+ @manifest ||= Rails.application.assets_manifest
74
81
  end
75
82
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IziLightup
4
- VERSION = '1.0.7'
4
+ VERSION = '1.0.12'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: izi_lightup
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - IzikAJ
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-08 00:00:00.000000000 Z
11
+ date: 2021-01-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Utils to speed up page load by using critical css &