Skip to content

Commit

Permalink
Added an minNumberOfMeasures option
Browse files Browse the repository at this point in the history
  • Loading branch information
gmetais committed May 28, 2014
1 parent 4a5a92d commit dbc70d4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Use this script to detect slow users on your website, so you can improve their n

```Slowness = Frustration```

**Think UX First!** Remove non-important things from your pages when the user has already been waiting for ages.
**Think UX First!** Remove non-important things from your interface when the user has already been waiting for ages.

## Usage

Expand All @@ -28,6 +28,20 @@ Before the first page is fully loaded, the average will be `null` (and `null` is
</script>
```

## Options

### minNumberOfMeasures (optional)

The `uxFirst` function will return `null` as long as the number of measures is not reached. Default is 1.

```js
// Wait for 3 measures before using uxFirst
if (uxFirst(3) < 10000) { ... }
```

It can help reducing yo-yo effect: the 1st page loads slowly - UXFirst helps accelerating the 2nd page and the average load-time gets under your limit - the 3rd page loads slowly again... The page content could look inconsistent if you use this script to remove a functionnality the user might be looking for.


## Use cases

- Don't load ads for users already having a slow navigation
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "UXFirst",
"description": "Small Javascript that tells you if a visitor is having a bad user experience because your site is slow",
"version": "0.1.0",
"version": "0.2.0",
"homepage": "https://github.com/gmetais/UXFirst",
"author": {
"name": "Gaël Métais",
Expand Down
24 changes: 13 additions & 11 deletions uxfirst.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,21 @@
}


global.uxFirst = function() {
var localData = readLocalStorage();
var sum = 0;
var dataLength = localData.length;
if(dataLength < 3) {
return null;
}
global.uxFirst = function(minNumberOfMeasures) {
var minNumber = minNumberOfMeasures || 1;
var localData = readLocalStorage();
var dataLength = localData.length;
var sum = 0;

if(dataLength < minNumberOfMeasures) {
return null;
}

for (var i=0, max=dataLength ; i<max ; i++) {
sum += localData[i].l;
}
for (var i=0, max=dataLength ; i<max ; i++) {
sum += localData[i].l;
}

return Math.round(sum / dataLength) || null;
return Math.round(sum / dataLength);
};

}(this));
4 changes: 2 additions & 2 deletions uxfirst.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dbc70d4

Please sign in to comment.