izi_lightup 1.0.5 → 1.0.10

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: 5073e2bc71a83daded40f2e37f2fef08c898ad94a0bcc3eaa9eb4e681c976f25
4
- data.tar.gz: 007fbd9ef27b45f3be8bfd3a9c4f9d0d5e75c58b9b088b058601d3ce7bd5d39b
3
+ metadata.gz: a1071982be30f35ea145d0e76811a9778ae0bbddb3a7e57316696efbbc64b564
4
+ data.tar.gz: 4e3077123033aabe258a343fba3759394e8cf2755d0d6333e82a5b25fc8ae3b8
5
5
  SHA512:
6
- metadata.gz: 2b64daf46ffba3f48ba0be2c3663be9eb140c4b15e486b3d0842ebfec7bfb393715c4d44753cae098f24479d2848a43e7f70f7aa85a48ee67dc2f3513e5b8a29
7
- data.tar.gz: 3ea7878407d5c0a244e2f03f6bcc3f5dc7915ea32a0376bd3999c73abf29ffd52e3f2a08cd94a84b9937e70fbe816a3bcefe9e5cb9168a2ddd497fb2a9f81cdb
6
+ metadata.gz: bd774cf44b3da70a34aef3c706e14e164c0a669b81f80859dcdb206e87271e2ad0b28db7a01114d8442092f80ad20f014c5174d2f7c543ad7ae154d201f8c6bd
7
+ data.tar.gz: a3d5c2b6ac75b7719bdc80732781ae8302eb545607f6cb8d4117013ea792db27b2287cc4fede9758e15f69621e06b520266088329b98faa3908e09ed7a147a55
@@ -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)
@@ -15,7 +15,6 @@
15
15
  _buildSubscriptions = (id, node) ->
16
16
  data = __required[id]
17
17
  return if data.loaded
18
- data.callbacks ||= []
19
18
 
20
19
  callback = node.onload
21
20
  node.onload = -> _onload(id)
@@ -32,25 +31,58 @@
32
31
 
33
32
  data.callbacks.push(callback) if typeof(callback) is 'function'
34
33
 
35
- window.miniRequire ||= (key, source_url, callback = undefined) ->
34
+ # window.miniRequire ||= (key, source_url, callback = undefined) ->
35
+ window.miniRequire ||= (params) ->
36
+ key = params.key || Math.random().toString(36).slice(2, 12)
37
+ callback = params.callback
38
+ source_url = params.src
36
39
  id = "source_#{key.replace(/[^a-z0-9_\-]+/ig, '_')}"
40
+ __required[id] ||= {loaded: false, callbacks: [], started: false}
37
41
 
38
- # subscribe only if already attached
39
- return _subscribe(id, callback) if __required[id]?
40
-
41
- __required[id] = {loaded: false, callbacks: []}
42
42
  # subscribe only if no source
43
- return _subscribe(id, callback) unless source_url?
43
+ return _subscribe(id, callback) unless source_url?.length > 0
44
+
45
+ # subscribe only if already attached & started
46
+ return _subscribe(id, callback) if __required[id].started
47
+
48
+ # mark as started
49
+ __required[id].started = true
44
50
 
45
51
  # attach script
46
52
  src = document.createElement('script')
47
53
  src.id = id
48
54
  src.async = true
49
55
  src.defer = true
56
+ src.as = params.as || 'style'
50
57
  src.src = source_url
51
58
  _buildSubscriptions(id, src)
52
59
  _subscribe(id, callback)
53
60
 
54
61
  document.body.appendChild(src)
55
62
  true
63
+
64
+ window.miniPreload ||= (key, source_url, callback = undefined) ->
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
+ _buildSubscriptions(id, src)
83
+ _subscribe(id, callback)
84
+
85
+ document.head.appendChild(src)
86
+ true
87
+
56
88
  ))(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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IziLightup
4
- VERSION = '1.0.5'
4
+ VERSION = '1.0.10'
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.5
4
+ version: 1.0.10
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-06 00:00:00.000000000 Z
11
+ date: 2020-12-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Utils to speed up page load by using critical css &
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  requirements: []
57
- rubygems_version: 3.0.3
57
+ rubygems_version: 3.1.2
58
58
  signing_key:
59
59
  specification_version: 4
60
60
  summary: Izi Lightup