Skip to content

Commit

Permalink
Preload tinymce assets
Browse files Browse the repository at this point in the history
Tinymce loads the editor content css and its plugins on initialize.
Since we init tinymce only when its visible it takes long to init the
editor. Using browser preload features to make sure the assets
are already loaded.
  • Loading branch information
tvdeyen committed Nov 23, 2023
1 parent a3104b5 commit f45d6bb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 14 additions & 0 deletions app/views/alchemy/admin/pages/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

<% content_for(:main_menu_style) { 'collapsed-menu' } %>

<% content_for :stylesheets do %>
<link rel="preload" href="/assets/tinymce/skins/alchemy/skin.min.css" as="style" />
<link rel="preload" href="/assets/tinymce/skins/alchemy/content.min.css" as="style" />
<% if Alchemy::Tinymce.init[:content_css] %>
<link rel="preload" href="<%= Alchemy::Tinymce.init[:content_css] %>" as="style" />
<% end %>
<% end %>

<% content_for :javascripts do %>
<% Alchemy::Tinymce.eagerload_plugins.each do |plugin| %>
<link rel="preload" href="/assets/tinymce/plugins/<%= plugin %>/plugin.min.js" as="script">
<% end %>
<% end %>

<% content_for(:toolbar) do %>
<div class="toolbar_buttons">
<div class="button_with_label">
Expand Down
11 changes: 8 additions & 3 deletions lib/alchemy/tinymce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ module Alchemy
module Tinymce
mattr_accessor :languages, :plugins

@@plugins = %w[alchemy_link anchor autoresize charmap code directionality fullscreen hr link lists paste tabfocus table]
DEFAULT_PLUGINS = %w[anchor charmap code directionality fullscreen hr link lists paste tabfocus table]

@@plugins = DEFAULT_PLUGINS + %w[alchemy_link]
@@init = {
skin: "alchemy",
width: "auto",
resize: true,
autoresize_min_height: "105",
autoresize_max_height: "480",
min_height: 220,
menubar: false,
statusbar: true,
toolbar: [
Expand All @@ -33,6 +34,10 @@ def init=(settings)
def init
@@init
end

def eagerload_plugins
@@plugins - DEFAULT_PLUGINS
end
end
end
end

0 comments on commit f45d6bb

Please sign in to comment.