izi_lightup 1.0.3 → 1.0.8

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: 90b753cd65a5809c20e73ff45888da3522becc09c96cc201716f559f9cc4ee6e
4
- data.tar.gz: 2a7081b56841e5d53c9f792ff17f7becdeef6f7eeb062d23a9d48067904ffbb5
3
+ metadata.gz: e07a49f206c6fb345cf0b7bbc5fbc2b97c7eb7ebe6d0a67b40249c0efcb8d3cb
4
+ data.tar.gz: c14d54784f732666060f993b8f3dd2c344e9c3cbf4247e836d9a7a92e395b1a0
5
5
  SHA512:
6
- metadata.gz: cb847e6b534e9b4796078be0ec691a8eeb530bbad14b1c964c8a138b6ebb5166642dfbf3d85e25bbfa25eeb397f98c7ab9fee2efc6bbea2c51036c226fe60d27
7
- data.tar.gz: aab2c944301d19dda2f2a088059a2c2bd63d509470b5ae8aebbb203fa474d87d8eb1803a98cf179128aa6e585074f2ef7cf41275a033fc6fb8eecafd50fb0513
6
+ metadata.gz: 45f511555379a877ce6da9caaea827e5fecb924e63ab2ab1410860fdcd484089fe4ca01fd3fe744b2a65691aca3190c0c795a8e8d96eaf9f326f4aa8263086cb
7
+ data.tar.gz: 7de673a26083b07cb3c8ad2828c6b6118930aaf71a0baa4e33cc7c0dd4fb57e017c572199b3f9ec8503e84e08f79f8017d1c12a475518c2dea86421083603476
@@ -1,2 +1,3 @@
1
- //= require cssrelpreload.js
1
+ // loadCSS should be always BEFORE cssrelpreload
2
2
  //= require loadCSS.js
3
+ //= require cssrelpreload.js
@@ -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)
@@ -34,13 +33,16 @@
34
33
 
35
34
  window.miniRequire ||= (key, source_url, callback = undefined) ->
36
35
  id = "source_#{key.replace(/[^a-z0-9_\-]+/ig, '_')}"
36
+ __required[id] ||= {loaded: false, callbacks: [], started: false}
37
37
 
38
- # subscribe only if already attached
39
- return _subscribe(id, callback) if __required[id]?
40
-
41
- __required[id] = {loaded: false, callbacks: []}
42
38
  # subscribe only if no source
43
- return _subscribe(id, callback) unless source_url?
39
+ return _subscribe(id, callback) unless source_url?.length > 0
40
+
41
+ # subscribe only if already attached & started
42
+ return _subscribe(id, callback) if __required[id].started
43
+
44
+ # mark as started
45
+ __required[id].started = true
44
46
 
45
47
  # attach script
46
48
  src = document.createElement('script')
@@ -1,10 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CriticalHelper
4
- def css_preload(name)
5
- link = content_tag :link, '', rel: 'preload', href: stylesheet_path(name), as: 'style', onload: 'this.rel="stylesheet"'
4
+ def css_preload(names)
5
+ return '' if names.blank?
6
+ names = Array.wrap(names)
7
+
8
+ link = stylesheet_link_tag(*names, rel: 'preload', as: 'style', onload: 'this.rel="stylesheet"')
6
9
  noscript = content_tag :noscript do
7
- content_tag :link, '', rel: 'stylesheet', href: stylesheet_path(name)
10
+ stylesheet_link_tag(*names)
8
11
  end
9
12
 
10
13
  link + noscript
@@ -24,14 +27,23 @@ module CriticalHelper
24
27
  inline_js('crit-utils/bundle.js').presence || '<!-- CRIT JS NOT FOUND! -->'.html_safe
25
28
  end
26
29
 
27
- def critical_css
28
- name = find_scoped_css('critical')
29
- return '<!-- CRIT CSS NOT FOUND! -->'.html_safe if name.blank?
30
+ def critical_css(params = {})
31
+ scope = params.fetch(:scope, 'critical')
32
+ name = find_scoped_css(scope)
33
+ stylesheets = Array.wrap(params.fetch(:stylesheets, []))
34
+ data = StringIO.new
30
35
 
31
- return inline_css(name) if Rails.env.production?
36
+ if name.blank?
37
+ # insert stylesheets directly if not crit css
38
+ data << '<!-- CRIT CSS NOT FOUND! -->'
39
+ data << stylesheet_link_tag(*stylesheets) if stylesheets.present?
40
+ else
41
+ data << inline_css(name)
42
+ data << css_preload(stylesheets) if stylesheets.present?
43
+ data << inline_js('crit-utils/measure.js') if Rails.env.development?
44
+ end
32
45
 
33
- # inject measure js for development
34
- inline_css(name) + inline_js('crit-utils/measure.js')
46
+ data.string.html_safe
35
47
  end
36
48
 
37
49
  def smart_picture(object, *args, **xargs, &block)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IziLightup
4
- VERSION = '1.0.3'
4
+ VERSION = '1.0.8'
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.3
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - IzikAJ
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-04 00:00:00.000000000 Z
11
+ date: 2020-12-09 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