Using sw-toolbox with gulp - service-worker

I read many tutorials about sw-toolbox and sw-precache.
The doubt i am having is :
When reading about sw-precache, i found out most tutorials are using gulp + sw-precache.
Whereas in sw-toolbox case, i saw the example and syntaxes given only for writing code in service-worker.js directly (no gulpfile code).
I am using gulp to automatically generate service-worker file .
So my main concern is to write code for sw-toolbox in gulp file directly so that i need not write sw-toolbox code after generating sw-precache with gulp
Please comment for doubts

You no need to write separate code manually for sw-toolbox. You can configure it using runtimeCaching option in sw-precache. As soon as you configured this option, sw-precache will insert sw-toolbox library in serviceWorker and adds different handlers to it. You can find more details from this link.

When using sw-precache it generates the service worker and you can't edit that file.
When using sw-precache I'd ignore sw-toolbox and just focus on how to configure sw-precache to cache static files and cache runtime files (I.e. cache images or pages as they are requested)

Related

how to generate html from swagger yaml file [duplicate]

There are only ugly HTML pages as download (HTML, HTML2 and dynamic all ugly), but the site, eg. edited https://app.swaggerhub.com/apis/{user}/{project}/{version}
(and many others!) offers pretty HTML interface... How to download this pretty HTML?
Complete and autonomous HTML code (file or zip of files).
I have a good and valid swagger.yaml or swagger.json file of my API, so another solution is to run a open sourse (plug and play!) tool with my API-description file.
The pretty:
The ugly:
The "pretty interface" on your screenshot is Swagger UI. It's free and open-source. There's a demo at http://petstore.swagger.io, where you can load your own YAML/JSON files from an URL and see how they would be rendered.
To use Swagger UI locally:
Go to https://github.com/swagger-api/swagger-ui and download the repository as ZIP:
Edit the dist\index.html file and change the line
url: "http://petstore.swagger.io/v2/swagger.json",
to the URL of your Swagger .json or .yaml file, e.g.
url: "http://api.mysite.com/swagger.json",
(Optional) Add/change other configuration parameters in the SwaggerUIBundle initialization code in dist\index.html.
Open the dist\index.html file in your browser to preview your API docs.
Note: If the spec does not load or "try it out" does not work, you probably need to enable CORS on the your server. See https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/cors.md and https://enable-cors.org.
Upload the files from the dist folder somewhere to your server - and now you have pretty API docs too!
Alternatively, SwaggerHub (which you mentioned) provides cloud hosting for Swagger specs among other things, and has Swagger UI integrated. You can import your Swagger .json/.yaml files there and have your API docs hosted on SwaggerHub. A free plan is available.
Thanks to #tleyden at swagger-ui/issues for good clues!
Use the index and assets folder of this project, https://github.com/okfn-brasil/swagger-ui-html

Create yeoman generator from json instead of prompts?

When I create a project, I first create a project.json file (used internally, not as part of some package). Then for some projects I run yeoman with our own custom generators.
What I would like is for yeoman to pick up my projects.json and read that instead of prompting me for settings.
Is this possible, and if so; how do I do this? Basically I think I need to know:
How do I load the file from the project-root into index.js (and defer to prompts if it doesn't exist)
How to I bind the properties from the json to 'this'.
A Yeoman generator is just a searchable and composable Node.js project running within the context of Yeoman.
As so, it can do anything.
So, if you want to write a generator reading a project.json configuration file to know what to generate - well just do it!
http://yeoman.io/authoring/

Minify using pom.xml

is it possible to minify css and js files inside a specific folder and then use the minified files for a file, let's say the index.html.? Im thinking of using the pom.xml then use the maven-minify-plugin and the replacer plugin but I can't find a good structure.
you should use the static-helper-maven-plugin from WUIC project (http://wuic.github.io/)
The maven plugin relies on WUIC to parse the index.html of your workspace, collects js/css used inside it, resolve them, minify them, aggregate them and rewrite the index.html with a version number in URLs to burst client cache in case of any change.
wiki: https://github.com/wuic/wuic/wiki/Process-at-build-time
The WUIC's website is generated optimized with this approach:
- source: https://github.com/wuic/wuic.github.io
- result: https://github.com/wuic/wuic.github.io/tree/master

Which files needs to be deployed from a Dart project?

I have an AngularJS project that I am thinking of migrating to Dart. I do not want to migrate the whole project in a big-bang, so I am looking for ways to run the two apps side-by-side.
The dart app will run on the root as index.html. The js app will run on a separate path, say '/jsApp'.
When I build a test project, it seems that the /build directory includes a lot of unnecessary files. Would I need to deploy the complete contents of the /build/web directory?
What is it that actually gets loaded? Do html files still get loaded at runtime or are they bundled into the main file?
Do I need main.dart.js as well as main.dart.precompiled.js? It seems that they are very large files for a trivial app. Is that to be expected?
It is still unclear to me how all these things hang together.
If you want to keep the generated files as small as possible, you should:
Make sure your pubspec.yaml includes the angular transformer, as explained here: Angulardart. Creating your first app
Your pubspec.yaml should look like this:
name: angular_dart_demo
version: 0.0.1
dependencies:
angular: 0.12.0
[...]
transformers:
- angular
html_files:
- web/my_html_template.html
- web/another_html_template.html
Build from the command line with pub build
This way you will get 800KB js, instead of 5MB js ;)
That's because Angular Dart uses mirrors and, as a result, the generated js code can get very big if you don't use the angular transformer.
I think html templates are copied to the build directory and will be requested at runtime.
You will have to merge the contents you get from "pub build" with your existing js application somehow.
I am using AngularJS with Dart controllers mixed in. You do not have to adapt your current project structure to use the pub build. Just use dart2js to compile the individual dart files and include the ".js" files in your page. You do not have to add the native dart script tag or include the dart bootstrap in your code. Just include a script tag for the generated js file (the only file you need) and it will do what you expect. I plan to write up a brief overview of this soon.
Normally the entire build directory needs to be deployed and there are normally no unnecessary files.
The *.precompiled.js files are not generated anymore in recent Dart builds (this was for CSP compliance).
What Dart version are you using?
If you build in debug mode also the source map files are generated in the build directory.
The browser loads the HTML file the user requests and then loads the script files references in <script> tags in this HTML and all other resources (img, css, ...)
I don't know if the build output of an Angular component with an external HTML-template file is inlined in the index.html or if they are copied as they are.

How do I override the Umbraco built-in media library methods to use s3?

I'm currently looking to move my Umbraco installation over to a load balanced setup. In order to do this, I need to move the Media library over to a CDN like Amazon's S3. I tested a few plugins that allow upload to s3, but they all list media files on the local file directory. This flat out will not work.
I was thinking I would write the code to browse the CDN, but how can I override the built-in media library code so that it uses my version instead? I didn't see a clear way to do this in the docs?
I am using this plugin: http://our.umbraco.org/projects/website-utilities/amazon-s3-media for amazon s3. The source code is here: https://bitbucket.org/gibedigital/umbraco-amazons3provider . He recently just updated the plugin. The plugin does not use the local file system. The developer was pretty responsive (and made a few updates for me when I asked).
However, I am adding to his project because his plugin did not allow saving within a predefined directory (amazon's virtual directories). But his source code is a start.
Good luck,
Robin

Resources