Lighthouse shows Does not respond with a 200 when offline in pwa but offline mode works - laravel-5

Quick question:
While the browser identifies my application as a valid PWA, as well as shows the install popup on the mobile browser. When it is audited in lighthouse, it shows Does not respond with a 200 when offline. I have validated that my app shell is cached from application(screenshots attached).
Details and Background:
I have built PWA on laravel using js and jquery. For asset compiling, I am using laravel mix and for PWA framework, I am using workbox. Also just to be clear I am not using any SPA framework/library .
In short I have built a custom spa using simpler components.
For PWA part this I am using workbox along with laravel mix.
Here are my service worker, manifest.json and mix file. note that I use sw.js and generate prod-sw.js using laravel-mix. This prod-sw.js is used in production
webpack.mix.js
require('laravel-mix-versionhash');
const mix = require('laravel-mix');
const workboxPlugin = require('workbox-webpack-plugin');
mix.webpackConfig({
output: {
filename: '[name].[contenthash].js',
publicPath: ''
},
plugins: [
new workboxPlugin.InjectManifest({
swSrc: 'sw.js', // more control over the caching
swDest: 'prod-sw.js', // the service-worker file name
importsDirectory: 'service-worker', // have a dedicated folder for sw files
exclude: [/\.map$/, /mix-manifest\.json$/, /mix\..*\.js$/, /manifest\.json$/, /service-worker\.js$/, /OneSignalSDKWorker\.js$/],
include: [/template\..*\.html$/, /\.js$/, /app\..*\.css$/, /logo.png$/],
templatedUrls: {
'/pwa': 'version-' + process.env.MIX_APP_VERSION,
},
})
],
})
mix.sass('resources/assets/sass/homepage.scss', 'public/css/')
.sass('resources/assets/sass/amp.scss', 'public/css/')
.sass('resources/assets/sass/app.scss','public/css/');
if (mix.inProduction()){
mix.versionHash();
}else{
mix.sourceMaps();
}
sw.js
var version = 123;
workbox.core.setLogLevel(workbox.core.LOG_LEVELS.silent);
workbox.skipWaiting();
workbox.clientsClaim();
const precacheController = new workbox.precaching.PrecacheController();
// Cache all scripts and stylesheets using an extension whitelist
workbox.routing.registerRoute(new RegExp('.(?:css|html|ico)$'),
workbox.strategies.staleWhileRevalidate({
cacheName: 'static-resources',
/* plugins: [
new workbox.expiration.Plugin({
maxEntries: 35,
maxAgeSeconds:1*24*60*60,
}),
], */
})
);
workbox.routing.registerRoute(new RegExp('.*(?:pwa\.|vendors\.).*\.js$'),
workbox.strategies.cacheFirst({
cacheName: 'js-cache-' + version,
plugins: [
new workbox.expiration.Plugin({
maxAgeSeconds: 8*24*60*60,
}),
],
})
);
workbox.routing.registerRoute('/pwa',
workbox.strategies.cacheFirst({
cacheName: 'html-cache-' + version,
})
);
workbox.precaching.precacheAndRoute(self.__precacheManifest);
manifest.json
{
"short_name": "Example",
"name": "Example",
"description": "Example App Description",
"gcm_sender_id": "1234567890",
"start_url" : "/pwa",
"display": "standalone",
"orientation": "portrait",
"theme_color": "#FFFFFF",
"background_color": "#FFFFFF",
"icons": [
{
"src": "https://cdn.example.com/assets/icons/icon-48x48.png",
"sizes": "48x48",
"type": "image/png"
}
]
}
A snapshot of manifest file, cache storage and lighthouse report is attached for your reference. Manifest.json, Cache Storage and Lighthouse

I have the same issue but without providing templateUrl property.
It works offline for me just in devTools but not fully offline and lighthouse has given the same results as yours.

Related

Tailwind on Laravel project doesn't contain all basic css classes [duplicate]

Okay, so I'm about to put my Laravel project in production. I tested everything on local host and it works perfectly using Tailwind 3. Yet, when I ran some PHP artisan commands to clear all cache and etc., migrate:fresh my database, and then ran npm run dev, I noticed that Tailwind removed the styles that I used in seeding blogs (I use seed to seed fake blog posts and view how they will look like).
For example I'm using the Typography Tailwind plugin with the utility-class prose and so on. When I ran migrate:fresh and the fake blog post deleted from database, then cleared Laravel cache, and ran npm run dev, I noticed that all the prose styles are being removed from app.css. Of course I don't want that because this should be applied on each and every blog post that I will submit in production.
So how can I stop Tailwind from deleting these styles? I currently have all that I need and I don't want anything else removed.
webpack.mix
const mix = require("laravel-mix");
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel applications. By default, we are compiling the CSS
| file for the application as well as bundling up all the JS files.
|
*/
mix.js("resources/js/app.js", "public/js")
.vue()
.postCss("resources/css/app.css", "public/css", [
require("postcss-import"),
require("tailwindcss"),
require("autoprefixer"),
]);
tailwind.config.js
const defaultTheme = require("tailwindcss/defaultTheme");
module.exports = {
darkMode: "class",
content: [
"./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php",
"./storage/framework/views/*.php",
"./resources/views/*.blade.php",
"./resources/views/components/*.blade.php",
"./resources/views/auth/*.blade.php",
"./resources/views/layouts/*.blade.php",
"./resources/js/components/categories/*.vue",
"./resources/js/components/**/*.vue",
],
theme: {
screens: {
xs: "364px",
sm: "430px",
sd: "644px",
md: "768px",
lg: "1024px",
xl: "1155px",
"2xl": "1280px",
},
extend: {
fontFamily: {
sans: ["Nunito", ...defaultTheme.fontFamily.sans],
},
typography: ({ theme }) => ({
white: {
css: {
"--tw-prose-body": theme("colors.white"),
"--tw-prose-headings": theme("colors.blue[400]"),
"--tw-prose-lead": theme("colors.purple[700]"),
"--tw-prose-links": theme("colors.blue[800]"),
"--tw-prose-bold": theme("colors.blue[800]"),
"--tw-prose-counters": theme("colors.blue[900]"),
"--tw-prose-bullets": theme("colors.blue[900]"),
"--tw-prose-hr": theme("colors.blue[800]"),
"--tw-prose-quotes": theme("colors.blue[800]"),
"--tw-prose-quote-borders": theme("colors.blue[800]"),
"--tw-prose-captions": theme("colors.blue[800]"),
"--tw-prose-code": theme("colors.blue[800]"),
"--tw-prose-pre-code": theme("colors.blue[200]"),
"--tw-prose-pre-bg": theme("colors.gray[900]"),
"--tw-prose-th-borders": theme("colors.blue[300]"),
"--tw-prose-td-borders": theme("colors.blue[200]"),
},
},
black: {
css: {
"--tw-prose-body": theme("colors.black"),
},
},
}),
},
},
plugins: [
require("#tailwindcss/forms"),
require("#tailwindcss/typography"),
],
};
Tailwind will only include the classes that it finds by scanning the files specified in the content array in tailwind.config.js. If you want to include additional classes that are only in your dynamic content, you can safelist those classes in your config. For example:
module.exports = {
...
safelist: [
'prose',
'prose-xl',
],
...
}
See: https://tailwindcss.com/docs/content-configuration#safelisting-classes

do you have to run npm run production when installing a new package?

I'm quite new, I need help.
https://github.com/tailwindlabs/tailwindcss-aspect-ratio
I have a laravel 8 project in production. I have installed this package and in local it works fine, but when I upload it to production it doesn't work. This package requires the installation of a plugin in the tailwind.config.js file.
const defaultTheme = require('tailwindcss/defaultTheme');
module.exports = {
purge: [
'./vendor/laravel/jetstream/**/*.blade.php',
'./storage/framework/views/*.php',
'./resources/views/**/*.blade.php',
],
theme: {
extend: {
},
},
variants: {
extend: {
opacity: ['disabled'],
},
},
plugins: [require('#tailwindcss/forms'), require('#tailwindcss/typography'), require('#tailwindcss/aspect-ratio'), ],
};
I have to run npm run production in production?
Thank you very much
does your webpack file create a .js file in the public directory? This is the file you need to upload after you run the npm run production
sometimes it helps to press ctrl when reloading as the browser may cache the old js files.

How to deploy Next.js with GraphQL backend on Zeit Now?

I have an Next.js/Express/Apollo GraphQL app running fine on localhost.
I try to deploy it on Zeit Now, and the Next.js part works fine, but the GraphQL backend fails because /graphql route returns:
502: An error occurred with your deployment
Code: NO_STATUS_CODE_FROM_LAMBDA
My now.json looks like:
{
"version": 2,
"builds": [
{ "src": "next.config.js", "use": "#now/next" },
{ "src": "server/server.js", "use": "#now/node" }
],
"routes": [
{ "src": "/api/(.*)", "dest": "server/server.js" },
{ "src": "/graphql", "dest": "server/server.js" }
]
}
Suggestions?
Here’s a complete example of Next.js/Apollo GraphQL running both on Zeit Now (as serverless function/lambda) and Heroku (with an Express server):
https://github.com/tomsoderlund/nextjs-pwa-graphql-sql-boilerplate
I was getting that error until I found on a solution on the Wes Bos slack channel.
The following worked for me, but it's possible you could be getting that error for a different reason.
I'm not sure why it works.
You can see it working here
cd backend
Run npm install graphql-import
Update scripts in package.json:
"deploy": "prisma deploy --env-file variables.env&& npm run writeSchema",
"writeSchema": "node src/writeSchema.js"
Note: For non windows users make sure to place space before &&
Create src/writeSchema.js:
const fs = require('fs');
const { importSchema } = require('graphql-import');
const text = importSchema("src/generated/prisma.graphql");
fs.writeFileSync("src/schema_prep.graphql", text)
Update src/db.js:
const db = new Prisma({
typeDefs: __dirname + "/schema_prep.graphql",
...
});
Update src/createServer.js:
return new GraphQLServer({
typeDefs: __dirname + '/schema.graphql',
...
});
Update src/schema.graphql:
# import * from './schema_prep.graphql'
Create now.json
{
"version": 2,
"name": "Project Name",
"builds": [
{ "src": "src/index.js", "use": "#now/node-server" }
],
"routes": [
{ "src": "/.*", "dest": "src/index.js" }
],
"env": {
"SOME_VARIABLE": "xxx",
...
}
}
Run npm run deploy to initially create schema_prep.graphql.
Run now
Another reply said this:
You should not mix graphql imports and js/ts imports. The syntax on the graphql file will be interpreted by graphql-import and will be ignored by ncc (the compiler which reads the __dirname stuff and move the file to the correct directory etc)
In my example 'schema_prep.graphql' is already preprocessed with the imports from the generated graphql file.
Hopefully this helps.

Vue Leverage browser caching of static assets

i am using Vue cli 3 and created a PWA using the PWA plugin. it all works pretty well and i am getting a Lighthouse Progressive Webb App score of 100 and a Performance score of 68 on a 3G connection.
the problem affecting my Performance score is that i fail to "Serve static assets with an efficient cache policy".
i also tested the app on webPageTest.org and it indicates a problem with "Leverage browser caching of static assets"
my website is https://www.istimuli.com/
i am assuming that i have to use runtime caching to cache these files. i use the GenerateSW plugin and tried the runtimeCaching option but it does not work.
i'd really appreciate any help to cache these files and getting the a higher Performance score.
thanks
here's my vue.config.js file
const { GenerateSW } = require('workbox-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const PurgecssPlugin = require('purgecss-webpack-plugin');
// var HtmlWebpackPlugin = require('html-webpack-plugin');
const glob = require('glob-all');
const path = require('path');
module.exports = {
pwa: {
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.css$/,
// use: [
// {
// loader: MiniCssExtractPlugin.loader,
// },
// "css-loader"
// ]
use: [
'style-loader',
{
loader: 'css-loader', options: {
minimize: true
}
}
]
}
]
},
plugins: [
new VueLoaderPlugin(),
new MiniCssExtractPlugin(),
new PurgecssPlugin({
paths: glob.sync([
path.join(__dirname, './public/index.html'),
path.join(__dirname, './src/assets/myJavascript/*.js'),
path.join(__dirname, './src/assets/css/*.css'),
path.join(__dirname, './src/components/*.vue'),
path.join(__dirname, './src/plugins/*.js'),
path.join(__dirname, './src/*.js'),
path.join(__dirname, './src/*.vue'),
])
}),
new GenerateSW({
runtimeCaching: [
{
urlPattern: new RegExp('^https://cors\.sdk.amazonaws.com/'),
handler: 'staleWhileRevalidate',
options: {
cacheableResponse: {
statuses: [0, 200]
}
}
},
{
urlPattern: /manifest/,
handler: 'staleWhileRevalidate',
options: {
expiration: {
maxEntries: 5,
maxAgeSeconds: 60 * 60 * 24 * 7,
}
}
}
]
})
],
}
}
edited
so i edited my server's htaccess file to apply cache control:
and things have improved somewhat:
i now only have the aws sdk file to contend with. i'm assuming that CORS has something to do with this. so any help regarding how to cache this would be appreciated.
further, checking the lighthouse report, i see that the aws sdk is indicated as not having an efficient cache policy - i assume that this is also linked to the CORS issue mentioned above?
there are 11 resources listed (i have only included 3 in the image) all are listed as having a cache lifespan of 30 days.is this sufficient or should it be longer to get a better lighthouse score?
i notice that the fonts file (with woff2 extension) is now cached by the browser even though i did not include this extension when i modified the htaccess file (see above).i find this confusing, any idea why its caching now and did not do so before i updated the htaccess file?
so i guess, for now my main concern is caching the aws sdk and any help in this regard would be appreciated.
thanks

Ionic 3 Cordova ajax calls fail on Windows 10 (UWP)

I have attempted to ask this previously, buy got no real answers, and have now been struggling for over a month.
I just cannot get my ajax calls to work on an Ionic 3 Cordova application built for a Windows 10 UWP. They can access localhost, but not any outside connections.
The application works fine on both Android and iOS.
I am trying to test this locally on my dev machine. I use a certificate (bought) to sign the application, install this certificate, build the application for Windows, and am able to open up the built CordovaApp.Windows10_1.0.1.1_x86.appxupload, and then double click the embedded CordovaApp.Windows10_1.0.1.1_x86.appx file to install, which completes successfully. The install indicates the app need internet access.
In the config.xml, I have the following tags, as suggested elsewhere...
<allow-navigation href="*" />
<access origin="*" />
However, when I run, the http.get call just returns 0 with no other information. I can run in Visual Studio, and look at the returned error object, and get no further info, apart from this 0 return.
I have run fiddler, enabled the https decryption as explained here, but all I see in the response header is
HTTP/1.0 200 Connection Established
FiddlerGateway: Direct
StartTime: 13:44:21.686
Connection: close
The result in the main view actually shows 200, so I don't think this is showing me anything real.
I am at a complete loss. I have no where else to search. What could I be missing?
Should I be able to use external ajax on a Windows 10 machine, when I have sideloaded the application as here? I haven't tried from the store yet, as I don't want to upload until I know it works.
Any suggestions desperately welcomed. Surely someone has had an Ionic 3 application accessing external ajax working?
Thanks in advance for any help
[UPDATE 1]
If I run the application on the same machine, just using Ionic serve (so it just runs in the browser rather than hosted in the UWP), the ajax calls also work fine.
[UPDATE 2]
I have now created a Cordova application using the Visual Studio template, so taking all other frameworks out of the equation.
I used vanilla JavaScript to do my rest call...
document.addEventListener('deviceready', callUrl, false);
function callUrl() {
console.log('callUrl');
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://myserveraddress.com/myapp/testroute');
xhr.send(null);
xhr.onreadystatechange = function () {
var DONE = 4; // readyState 4 means the request is done.
var OK = 200; // status 200 is a successful return.
if (xhr.readyState === DONE) {
if (xhr.status === OK)
console.log(xhr.responseText);
} else {
console.log('Error: ' + xhr.status);
}
}
};
I run this in the debugger, and even here I get an error (status code of 0).
Another thing I noticed when I open up the build package and look at the cordova_plugins.js file..
My Ionic app has the following...
cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [
{
"id": "cordova-plugin-console.logger",
"file": "plugins/cordova-plugin-console/www/logger.js",
"pluginId": "cordova-plugin-console",
"clobbers": [
"cordova.logger"
]
},
{
"id": "cordova-plugin-console.console",
"file": "plugins/cordova-plugin-console/www/console-via-logger.js",
"pluginId": "cordova-plugin-console",
"clobbers": [
"console"
]
},
{
"id": "cordova-plugin-device.device",
"file": "plugins/cordova-plugin-device/www/device.js",
"pluginId": "cordova-plugin-device",
"clobbers": [
"device"
]
},
{
"id": "cordova-plugin-device.DeviceProxy",
"file": "plugins/cordova-plugin-device/src/windows/DeviceProxy.js",
"pluginId": "cordova-plugin-device",
"merges": [
""
]
},
{
"id": "cordova-plugin-splashscreen.SplashScreen",
"file": "plugins/cordova-plugin-splashscreen/www/splashscreen.js",
"pluginId": "cordova-plugin-splashscreen",
"clobbers": [
"navigator.splashscreen"
]
},
{
"id": "cordova-plugin-splashscreen.SplashScreenProxy",
"file": "plugins/cordova-plugin-splashscreen/www/windows/SplashScreenProxy.js",
"pluginId": "cordova-plugin-splashscreen",
"runs": true
},
{
"id": "cordova-plugin-statusbar.statusbar",
"file": "plugins/cordova-plugin-statusbar/www/statusbar.js",
"pluginId": "cordova-plugin-statusbar",
"clobbers": [
"window.StatusBar"
]
},
{
"id": "cordova-plugin-statusbar.StatusBarProxy",
"file": "plugins/cordova-plugin-statusbar/src/windows/StatusBarProxy.js",
"pluginId": "cordova-plugin-statusbar",
"runs": true
},
{
"id": "ionic-plugin-keyboard.KeyboardProxy",
"file": "plugins/ionic-plugin-keyboard/src/windows/KeyboardProxy.js",
"pluginId": "ionic-plugin-keyboard",
"clobbers": [
"cordova.plugins.Keyboard"
],
"runs": true
}
];
module.exports.metadata =
// TOP OF METADATA
{
"cordova-plugin-console": "1.0.5",
"cordova-plugin-device": "1.1.4",
"cordova-plugin-splashscreen": "4.0.3",
"cordova-plugin-statusbar": "2.2.2",
"cordova-plugin-whitelist": "1.3.1",
"ionic-plugin-keyboard": "2.2.1"
};
// BOTTOM OF METADATA
});
Now, I notice every plugin in the module.exports.metadata also has an entry in the module.exports EXCEPT for cordova-plugin-whitelist!
If I open the same file for the Corvoda application created in VS, I see the following...
cordova.define('cordova/plugin_list', function(require, exports, module) {
module.exports = [];
module.exports.metadata =
// TOP OF METADATA
{
"cordova-plugin-whitelist": "1.2.2"
};
// BOTTOM OF METADATA
});
So this has nothing else for the whitelist plugin as well
Could there be something missing here?? Could this white-list plugin not be installed correctly?
I had a similar situation where my ajax calls worked fine in TEST, but when I moved to PROD, they would fail.
The answer was finally tracked down as a missing intermediary certificate on the server I was trying to access. TEST had the cert, PROD did not.
I hope this helps.

Resources