Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance issue with bootstrap datepicker

Not sure if it's a setting I moved, but I'm having an issue with bootstrap datepicker loading a lot of localization files on every single page I visit of my project, even if no component in the page uses a datepicker element.

I get something like this from my development.log:

Started GET "/assets/bootstrap-datepicker/locales/bootstrap-datepicker.ar.js?body=1" for 127.0.0.1 at 2014-07-29 00:14:15 -0700


Started GET "/assets/bootstrap-datepicker/locales/bootstrap-datepicker.az.js?body=1" for 127.0.0.1 at 2014-07-29 00:14:15 -0700


Started GET "/assets/bootstrap-datepicker/locales/bootstrap-datepicker.bg.js?body=1" for 127.0.0.1 at 2014-07-29 00:14:15 -0700


...


Started GET "/assets/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.js?body=1" for 127.0.0.1 at 2014-07-29 00:14:16 -0700


Started GET "/assets/bootstrap-datepicker/locales/bootstrap-datepicker.zh-TW.js?body=1" for 127.0.0.1 at 2014-07-29 00:14:16 -0700

A lot of lines, from AR to zh-TW, which as the names denote, they're the individual localisation files for each language/region.

This isn't a problem for my production server, but on development it's really significant. Under Vagrant, loading those files takes somewhere around 7700ms before every page, and under VMware around 2300ms.

My application.rb only has the following:

config.action_controller.include_all_helpers = false

And my gemfile:

source 'https://rubygems.org'

gem 'rails', '4.1'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
gem 'haml-rails'
gem 'jquery-turbolinks'
gem 'jquery-datatables-rails', git: 'https://github.com/rweng/jquery-datatables-rails.git'
gem 'jquery-ui-rails'
gem 'highcharts-rails'
gem 'rack-mini-profiler'
gem 'devise'
gem 'highstock-rails'
gem 'yaml_db', github: 'jetthoughts/yaml_db', ref: 'fb4b6bd7e12de3cffa93e0a298a1e5253d7e92ba'
gem 'hirb'

gem 'therubyracer'
gem 'less-rails'
gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git', :branch => 'bootstrap3'

gem 'bootstrap-datepicker-rails', :require => 'bootstrap-datepicker-rails', :git => 'git://github.com/Nerian/bootstrap-datepicker-rails.git'

group :development, :test do
  gem 'sqlite3'
end
group :production do
  gem 'mysql2'
end

Any clues what may be the issue?

like image 386
dev404 Avatar asked Jul 29 '14 07:07

dev404


1 Answers

Found the solution. I simply had to narrow what I was loading from the datepicker javascript, as by default, it loads EVERYTHING.

Normally I had something like this in my application.js:

//= require bootstrap-datepicker

All I had to do was change it to:

//= require bootstrap-datepicker/core

This one won't load ALL the localization files, and instead it will simply load the default one, English.

like image 129
dev404 Avatar answered Oct 26 '22 10:10

dev404