izi_lightup 1.0.2 → 1.0.7

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: 971ccdb8cdb13d496b89ae7e2cd8ebe7847f55be9c4549ac4915741ed10edaab
4
- data.tar.gz: 7c896250889a297cbd849b310fa6bda450e6258fb30f3d8fb5eeff6fe072b29e
3
+ metadata.gz: 53eb89af799d0a5092528a4159f8f67f042e3ce4eb30903fba949e116857c924
4
+ data.tar.gz: 9ae8a7f1c98d7b35fd4c31653f516845d190e3cd8d2642388765c44c5fee8e6f
5
5
  SHA512:
6
- metadata.gz: b36f6456c5b05096e32166f658b4e5f1452bd530bc90d0ce9f817b19f768599092ed623e88dce68d2c7a1b44dd4491ffdc52a6959ca7cc24ebcd4d3608ff2f1e
7
- data.tar.gz: d025222d627f6a9621608db1fd8fa7127938a9e749dc9bfc263e8a9c18afb912aa57ec6ebc86712fabd564e40b5972362a583d8924cd8992a556e54eaca8e595
6
+ metadata.gz: 1a424b4f1b656fd599cdb0e73a8e30dd86116ae4bf73fba550fdafea3eae52e7460627bc8f014fd8d8fb7d2e94a39d2fd7ce6ffc5825cc308197ccbc41473040
7
+ data.tar.gz: 80befcb20e4b325c8362a8da9f8b9b7f9d19573ea0cadc5e7d441f9a5b9c6ef59432b6e63ff0b435111bfe847343a320a279ad7a7d2db9b0850643e5d0894da0
@@ -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,22 @@ 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
30
+ def critical_css(params = {})
28
31
  name = find_scoped_css('critical')
29
- return '<!-- CRIT CSS NOT FOUND! -->'.html_safe if name.blank?
32
+ stylesheets = Array.wrap(params.fetch(:stylesheets, []))
33
+ data = StringIO.new
30
34
 
31
- return inline_css(name) if Rails.env.production?
35
+ if name.blank?
36
+ # insert stylesheets directly if not crit css
37
+ data << '<!-- CRIT CSS NOT FOUND! -->'
38
+ data << stylesheet_link_tag(*stylesheets) if stylesheets.present?
39
+ else
40
+ data << inline_css(name)
41
+ data << css_preload(stylesheets) if stylesheets.present?
42
+ data << inline_js('crit-utils/measure.js') if Rails.env.development?
43
+ end
32
44
 
33
- # inject measure js for development
34
- inline_css(name) + inline_js('crit-utils/measure.js')
45
+ data.string.html_safe
35
46
  end
36
47
 
37
48
  def smart_picture(object, *args, **xargs, &block)
@@ -33,19 +33,21 @@ module IziLightup
33
33
  end
34
34
 
35
35
  def raw_source(asset_path)
36
- return find_sources_fallback(asset_path) unless manifest.respond_to?(:find_sources)
36
+ return find_sources_fallback(asset_path) if old_manifest?
37
37
 
38
38
  manifest.find_sources(asset_path).first&.html_safe
39
39
  end
40
40
 
41
+ def old_manifest?
42
+ !manifest.respond_to?(:find_sources)
43
+ end
44
+
41
45
  def manifest
42
46
  @manifest ||= Rails.application.assets_manifest
43
47
  end
44
48
 
45
49
  def find_sources_fallback(asset_path)
46
- src = manifest.send(:find_asset, asset_path)
47
-
48
- src&.source&.html_safe || ''
50
+ Rails.application.assets.find_asset(asset_path)&.source&.html_safe
49
51
  end
50
52
  end
51
53
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IziLightup
4
- VERSION = '1.0.2'
4
+ VERSION = '1.0.7'
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.2
4
+ version: 1.0.7
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-10-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Utils to speed up page load by using critical css &
@@ -36,7 +36,8 @@ files:
36
36
  - vendor/assets/javascripts/cssrelpreload.js
37
37
  - vendor/assets/javascripts/loadCSS.js
38
38
  homepage: https://bitbucket.org/netfixllc/izi_lightup
39
- licenses: []
39
+ licenses:
40
+ - MIT
40
41
  metadata: {}
41
42
  post_install_message:
42
43
  rdoc_options: []
@@ -53,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
54
  - !ruby/object:Gem::Version
54
55
  version: '0'
55
56
  requirements: []
56
- rubygems_version: 3.0.3
57
+ rubygems_version: 3.1.2
57
58
  signing_key:
58
59
  specification_version: 4
59
60
  summary: Izi Lightup