Tag: Javascript

Rails 3.1 beta rc2 – Could not find a JavaScript runtime

Uruchamiając aplikację na Railsach 3.1beta rc2 możemy dostać taki błąd:

.rvm/gems/ruby-1.9.2-head@gems/execjs-1.1.1/lib/execjs/runtimes.rb:43:
in `autodetect': Could not find a JavaScript runtime. 
See https://github.com/sstephenson/execjs for a list of available runtimes.
(ExecJS::RuntimeUnavailable)

Rozwiązanie jest bardzo proste, dodajemy therubyracer do gemfilea:

gem 'therubyracer'

odpalamy:

bundle install

i problem znika :)

 

Rails + Passenger vs htaccess, cache i gzip (mod_deflate)

Dzisiaj będzie krótko i treściwie. Co chcemy osiągnąć? Chcemy:

  • Serwować statyczny cache z subkatalogu /cache katalogu /public (czyli /public/cache)
  • Kompresować gzipem pliki CSS i JS

Jak?

Tworzymy plik .htaccess w katalogu /public naszego projektu a następnie wklejamy do niego to:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^([^.]+)/$
RewriteRule ^[^.]+/$ /%1 [QSA,L]

RewriteCond %{THE_REQUEST} ^(GET|HEAD)
RewriteCond %{REQUEST_URI} ^([^.]+)$
RewriteCond %{DOCUMENT_ROOT}/cache/%1.html -f
RewriteRule ^[^.]+$ /cache/%1.html [QSA,L]

RewriteCond %{THE_REQUEST} ^(GET|HEAD)
RewriteCond %{DOCUMENT_ROOT}/cache/index.html -f
RewriteRule ^$ /cache/index.html [QSA,L]

AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:pdf|doc)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:avi|mov|mp3|mp4|rm)$ no-gzip dont-vary

Tyle - od teraz nasze aplikacje mają zarówno cache z subkatalogu public/ jak i kompresję gzipem - dzięki czemu strona działa szybciej i zjada mniej łącza.

Copyright © 2024 Closer to Code

Theme by Anders NorenUp ↑