用 JavaScript Switcher 快速啟用 JavaScript...

Update:這篇的切換會保留到下次 (重新啟動瀏覽器後還是有效),關於要清掉的請參考「改用 Simple JavaScript Toggle 切換 Google Chrome 的 JavaScript」這邊。

在上一篇「把 Google Chrome 預設的 JavaScript 關閉,開白名單...」提到把在 Google Chrome 裡把 JavaScript 關掉改用白名單管理有很多好處,但還是有個問題比較討厭,就是臨時要打開 JavaScript 的步驟很麻煩,而且還要記得拔掉。

而「JavaScript Switcher」就是解決這個問題的好工具:遇到需要 JavaScript 才會正常運作的網頁時,可以先按一下 icon 讓他開啟 JavaScript (然後他會自己 reload 頁面),這個設定一直都會生效,直到你重開瀏覽器時就會自己洗掉,不需要擔心會忘記拔掉

前人把這些工具都做好了,愉快... XD

把 Google Chrome 預設的 JavaScript 關閉,開白名單...

就如同標題寫得,把 Google Chrome 的 JavaScript 關閉,然後開白名單,這樣的好處有不少:

  • 大幅增加載入的速度:即使用了 Ghostery,還是有不少 JavaScript 的程式被執行到。
  • 增加網站安全性:雖然 Google Chrome 的 sandbox 不算差,但完全不要跑 JavaScript 可以擋下很多安全性問題。
  • 對 anti-adblock 機制的抵抗力:意外的發現不少 anti-adblock 機制都是透過 JavaScript 偵測,而這個方法直接擋下來了。
  • 對 infinite-scrolling 機制的抵抗力:有不少新聞網站拉到最底端會自動讀取相關的新聞 (或是類似的機制),我其實很不喜歡這樣的機制... 直接省下來 XD

另外就是透過 Google Chrome 本身的同步機制,其實可以設一次所有機器都生效,不算太麻煩。沒意外的話應該會一直用下去...

AWS Lambda 支援 Node.js 4.3

AWS 宣佈 Lambda 支援 Node.js 4.3:「AWS Lambda Supports Node.js 4.3」:

You can now develop your AWS Lambda functions using Node.js 4.3.2 in addition to Node.js 0.10.4.

另外同步在「Node.js 4.3.2 Runtime Now Available on Lambda」這邊也有文章介紹。

這樣總算可以拿出新的套件以及語法了...

V8 JavaScript 引擎將支援 WebAssembly

V8 JavaScript 引擎宣佈支援 WebAssembly:「Experimental support for WebAssembly in V8」。

依照說明,看起來在 Google Chrome 51 之後的版本 (目前是在 Chrome Canary) 可以打開 chrome://flags#enable-webassembly 啟用 WebAssembly 測試。

目前還是只有想到電玩遊戲之類的用途...

Google Analytics 推出 Autotrack 工具幫助整合

Google Analytics 推出了 Autotrack 工具,讓開發者更容易整合:「Introducing Autotrack for analytics.js」。

可以看到有些地方是將 Unobtrusive JavaScript 的概念拿出來用,像是 Declarative event tracking 這邊用 data attribute:

<button data-event-category="Video" data-event-action="play">Play</button>

對於還沒有針對 Google Analytics 客製化整合的人都會有幫助:

While anyone could use and benefit from autotrack, the library is primarily geared toward sites that do not customize their current analytics implementation and would like to take advantage of the features described in this article.

GitHub 上的說明可以看到預設了非常多常用的功能,像是 socialTracker 預設就有提供 FacebookTwitter (咦,你們自己家的 Google Plus 呢?)

不過這個軟體有免責條款,不屬於 GA 的正式產品:

The autotrack library is not an official Google Analytics product and is not covered by Google Analytics Premium support. Developers that choose to use this library are responsible for ensuring that their implementation meets the requirements of the Google Analytics Terms of Service and the legal obligations of their respective country.

看起來先進很多,之後自己開發東西拿出來用用...

RightScale 介紹的 TrackJS

RightScale 介紹了 TrackJS 這個服務:「Why do we use TrackJS」。

可以看發生錯誤的 stack:

有錯誤的綜合分析:

然後可以將 minified 的 JS 試著展開,讀起來會比較容易,不過沒看到對 source map 的支援?

價位上比 Rollbar 低不少 ($249 在 TrackJS 可以記 10M,但在 Rollbar 只能記 1.5M),不過 Rollbar 支援的平台比較多 (台灣也有代理商可以開發票處理帳務),也許找機會用看看 TrackJS 再決定吧。

jQuery 2.2 與 1.12 釋出

jQuery 放出 2.2 與 1.12,預定是 3.0 前的最後一個 major release,之後不會加 feature 了:「jQuery 2.2 and 1.12 Released」。

主要的效能改善來自一年前對 Sizzle 的 patch:「Check existing selector cache and skip matchesSelector when possible · Issue #315 · jquery/sizzle」,針對 :visible:hidden 的效能改善,速度大約是原來的 17 倍:

Performance of the selector engine has improved thanks to a shortcut path that immediately uses precompiled Sizzle selectors when the selector cannot be processed by the native querySelectorAll or matchesSelector methods. This results in a significant speedup in some real-world cases.

距離上次出版 2.1.4 與 1.11.3 好久了 (2015 年 4 月的事情):「jQuery 1.11.3 and 2.1.4 Released – iOS Fail-Safe Edition」。

JavaScript Errors Notifier 移除 FairShare 了

先前提到 JavaScript Errors Notifier 裡有 FairShare 的問題:「改用沒有 FairShare 版本的 JavaScript Errors Notifier」。

剛剛在 Urgent: Make javascript-errors-notifiers less invasive 這邊看到作者已經從 Google Web Store 上面的版本拿掉 FairShare 了:

And yes, it was completely removed.

另外也得到一些數字:

This decision is about -$5000 of my yearly income, but, anyway, it makes me feel better :)

V8 的 Math.random() 亂度不足的問題

在「TIFU by using Math.random()」這篇看到作者踩到地雷,於是在討論 V8 EngineMath.random() 的亂度不足。

其實這個問提早在 2012 年就有人在 StackOverflow 上詢問:「Why is Google Chrome's Math.random number generator not *that* random?」,而且也回答得很清楚。

而 Mozilla 這邊在 2006 年也被提出了類似的問題:「Bug 322529 - Upgrade Math.random() to a better algorithm, such as Mersenne Twister」。

文章中間花了許多篇幅講 PRNG 的介紹,以及 cycle length 的說明,重點其實在結論的部份。

主要是因為 V8 Engine 的 Math.random() 實作的是 MWC1616 演算法 (Fast random number generation using 128 bit multimedia extension registers on Pentium class machines),而這個演算法用起來也綁手綁腳:

If you’re only using the most significant 16 bits it has a very short effective cycle length (less than 2³⁰).

有兩個方向可以改善 (不衝突的方向),一個是使用 CSPRNG (保證有極長的 cycle length),另外一個請求 V8 Engine 把 Math.random() 的演算法換掉,像是 MT19937 這類 cycle length 超級長的演算法。

不知道後續有沒有機會改善...