GithubHelp home page GithubHelp logo

compact's People

Contributors

bengourley avatar mantasmikal avatar rymate1234 avatar serby avatar voronchuk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

compact's Issues

Files served before copy is complete

When I have multiple scripts and I use compactJsHtml() in debug mode, I often get

Uncaught SyntaxError: Unexpected end of input

in my browser console for one or more scripts. It turns out that the script hasn't been completely copied from src to dest before the page is served.

I see that the copying is being done using util.pump, which has been deprecated in favor of stream.pipe. So that may fix the issue.

Multiple compactJsHtml functions

Because there's only one compactJsHtml function, compact doesn't allow you to create, say, one set of JS files to be concatenated in the <head> and another set to be concatenated at the end of the <body>.

How about an API that looks like this:

// Express configuration
app.use(compact.middleware({
  head: ['namespace1'],
  foot: ['namespace2']
});

// Jade template
html
  head
  != compact.head.html()
  body
    block content
    != compact.foot.html()

Wrong Should.js code pulled in...

The ThrowError code is missing from should lib.

If you clone the latest version of should.js and copy the should.js lib file over the top of the exciting one. The Tests run fine.

But installing it from npm does not seem to bring in the lastest version.

Using with Express 3.x

Just a quick heads up that anyone wanting to use this on Express 3.x needs to change line 201 in compact.js as app.helpers are not used anymore. You simply have to change it to app.locals

I would create a pull request but it seems trivial for one simple word change

Third-party scripts (Feature)

It would be nice to have a feature in compact that lets you reference third party scripts.. e.g jQuery on Google's CDN, Google Maps API, various share widgets (Twitter, +1, Facebook).

e.g:

compact.addNamespace('find-us')
    .addThirdPartyJs('http://maps.google.com/maps/api/js?sensor=true')
    .addJs('/js/my-map.js');

Output:

<script src='http://maps.google.com/maps/api/js?sensor=true'></script>
<script src="/js/compact/find-us.js"></script>

Similar functionality is easily achievable with Jade template inheritance, but I think it would be better if all of the frontend JS was organised in one place. What do you think?

Timestamp update on compacted JS on each request

Trying to migrate from minj and I encountered this issue...

Every time I request a page in the browser, the timestamp of the compacted js file(s) is updated. This was causing nodemon to restart the server on each request. I've added the compated directory to my .npmignore which prevents this issue, but I am confused as to why the timestamp is updated, and don't think it should be.

Scripts not in order

I'm adding scripts (using addJs()) to my namespace, but in the compacted file, the order isn't maintained. Example:

compact.addNamespace('edit');
compact.ns.edit
    .addJs('ace/ace.js')
    .addJs('ace/mode-html.js')
    .addJs('ace/mode-css.js')
    .addJs('ace/mode-javascript.js')
    .addJs('edit.js');

The scripts are added to the compacted file in this order: mode-html.js -> mode-css.js -> mode-javascripts.js -> edit.js -> ace.js

I was wondering if there is any way to fix this? Thanks.

Helper is not scoped to request, but to app

The helpers compactJsHtml() and compactJs() are attached to app.helpers, which means that they exist for the duration of the application, not the request (as expected).

Here is a problem that is causes:

app.js

app.get('/', routes.index); // No JS on page
app.get('/edit', compact.js(['edit']), routes.edit); // `edit` JS on the page

layout.jade (inherited by index and edit views)

//...
if (compactJsHtml !== 'undefined')
  !=compactJsHtml()
//...
  • If you view / then the page is output as desired: no JS.
  • If you view /edit then the page is output as desired: edit JS
  • Subsequent views to / output the edit JS because compactJsHtml is still defined from the request to
    /edit

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.