<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Ansh Varun]]></title><description><![CDATA[Your go-to blog for tech trends and self-improvement tips. Stay ahead with insights and practical advice to boost your productivity and keep growing in the fast]]></description><link>https://blog.anshvarun.com</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 16:41:15 GMT</lastBuildDate><atom:link href="https://blog.anshvarun.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Mastering Nuxt and Capacitor Integration: A Resource Toolkit]]></title><description><![CDATA[Create resources folder in root directory.

Add icon.png with size - 1024x1024 px Add splash.png with size - 2732x3732 px

So we have placed icon and splash in resources folder, now we need these in all sizes compatible with our android and ios platf...]]></description><link>https://blog.anshvarun.com/mastering-nuxt-and-capacitor-integration-a-resource-toolkit</link><guid isPermaLink="true">https://blog.anshvarun.com/mastering-nuxt-and-capacitor-integration-a-resource-toolkit</guid><category><![CDATA[Nuxt]]></category><category><![CDATA[capacitor]]></category><category><![CDATA[resources]]></category><category><![CDATA[Cordova]]></category><dc:creator><![CDATA[ANSH VARUN]]></dc:creator><pubDate>Fri, 04 Oct 2024 07:46:32 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/_zKxPsGOGKg/upload/9485e47f2db018714c77bf6381b327c6.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<ul>
<li><p>Create <em>resources</em> folder in root directory.</p>
</li>
<li><p>Add <em>icon.png</em> with size - 1024x1024 px Add <em>splash.png</em> with size - 2732x3732 px</p>
</li>
<li><p>So we have placed icon and splash in resources folder, now we need these in all sizes compatible with our android and ios platforms.</p>
</li>
<li><p>Lets add script to generate it and then <em>sync</em> it to platform.</p>
</li>
<li><p>Add the following command to scripts in <strong>package.json</strong> file of nuxt app</p>
</li>
</ul>
<blockquote>
<p>"resources": "cordova-res-generator -p android,ios &amp;&amp; node resources/sync.js android"</p>
</blockquote>
<p>As we see, we have used <a target="_blank" href="https://www.npmjs.com/package/cordova-res-generator#installation"><strong>cordova-res-generator</strong></a> so lets install this generator by</p>
<blockquote>
<p>yarn add --dev cordova-res-generator</p>
</blockquote>
<p>We have successfully add res-generator now we are ready to go but we still have <strong>node resources/sync.js android</strong></p>
<p>This will sync the resources to android platform using sync.js, so lets add sync.js in resources where we have added our icon and splash</p>
<blockquote>
<p><a target="_blank" href="https://github.com/anshcena/blog/blob/main/nuxt-capacitor/sync.js">Sync.js</a></p>
</blockquote>
<p>Copy the code from above mentioned <a target="_blank" href="https://github.com/anshcena/blog/blob/main/nuxt-capacitor/sync.js">Sync.js</a> to generate sync.js inside resources.</p>
<p>so our resources will have these 3 :</p>
<p><img src="https://github.com/anshcena/blog/blob/main/nuxt-capacitor/img/sync%20file.jpg?raw=true" alt="Structure resources" /></p>
<p>We are ready to generate and sync now</p>
<blockquote>
<p>yarn resources</p>
</blockquote>
<p>🎉 Resources are generated and sync to platfrom - android 🎉</p>
<p>For <strong>iOS</strong> , we can make change in scripts of package.json as <strong>node/sync.js ios</strong></p>
<p><em>Make sure to put logo in splash screen in middle as well as small for better resource generated results and optimized images.</em></p>
]]></content:encoded></item><item><title><![CDATA[Storage of Web]]></title><description><![CDATA[Web storage provides essential benefits to modern application to store data in browser resulting in improved user experience. Sometimes, internet connections can be unreliable or unavailable, which is why offline functionality and reliable performanc...]]></description><link>https://blog.anshvarun.com/storage-of-web</link><guid isPermaLink="true">https://blog.anshvarun.com/storage-of-web</guid><category><![CDATA[localstorage]]></category><category><![CDATA[sessionStorage]]></category><category><![CDATA[indexeddb]]></category><category><![CDATA[storage]]></category><category><![CDATA[web storage api]]></category><category><![CDATA[web]]></category><dc:creator><![CDATA[ANSH VARUN]]></dc:creator><pubDate>Sat, 21 Sep 2024 20:13:08 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/t0SlmanfFcg/upload/f9aa3f60257bfc4567ec9e5e14101b2b.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Web storage provides essential benefits to modern application to store data in browser resulting in improved user experience. Sometimes, internet connections can be unreliable or unavailable, which is why offline functionality and reliable performance are common.</p>
<p>Web storage allows data to persist across sessions and store locally without needing a server. Having storage available on the client side is crucial for many standard web features. Using browser cache and other storage techniques can substantially improve the user experience.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1726949281092/4e1b3525-77c0-464f-821f-f9a764b996a7.jpeg" alt class="image--center mx-auto" /></p>
<h3 id="heading-session-storage">Session Storage</h3>
<p>Session storage stores data in browser until page session ends i.e <code>sessionStorage</code> is cleared when the window is closed.</p>
<ul>
<li><p>Data can only be accessed from same source i.e its per origin/domain.</p>
</li>
<li><p>Session lifecycle only stays with browser tab and cleared when browser tab is closed.</p>
</li>
<li><p>The storage limit is larger than cookies, around 5MB</p>
</li>
</ul>
<blockquote>
<p>Only preferred for storing temporary data like user activities that are required in next actions like user choices, payment info, login sessions, cart choices etc.</p>
</blockquote>
<p>Example</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Save data to sessionStorage</span>
sessionStorage.setItem(<span class="hljs-string">'rememberMe'</span>, <span class="hljs-string">'true'</span>);

<span class="hljs-comment">// Get saved data from sessionStorage</span>
<span class="hljs-keyword">let</span> name = sessionStorage.getItem(<span class="hljs-string">'rememberMe'</span>);
</code></pre>
<h3 id="heading-local-storage">Local Storage</h3>
<p>Local storage is web storage API that allow sites and apps to store data in key - value pair format in the browser. This data lasts forever, meaning it never expires. Data is stored in browser. This storage is persistent and global.</p>
<ul>
<li><p>Data can be only cleared by site functionality or deleted by browser’s settings.</p>
</li>
<li><p>Access to data can be done frequently without making network requests.</p>
</li>
<li><p>Locale storage can store <strong>up to 10 MB of data per origin</strong> (domain and protocol).</p>
</li>
</ul>
<blockquote>
<p>Preferred for storing larger data of apps like auth tokens, preferences or caching when user needs to persist data locally.</p>
</blockquote>
<p>Example</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// save data in local storage</span>
<span class="hljs-keyword">const</span> user = { 
    <span class="hljs-attr">username</span>: <span class="hljs-string">'murali_saran'</span>,
    <span class="hljs-attr">remember</span>: <span class="hljs-literal">true</span>,
    <span class="hljs-attr">darkMode</span>: <span class="hljs-literal">true</span>,
    <span class="hljs-attr">lang</span>: <span class="hljs-string">'es'</span>
};

<span class="hljs-built_in">localStorage</span>.setItem(<span class="hljs-string">'details'</span>, <span class="hljs-built_in">JSON</span>.stringify(user));

<span class="hljs-comment">// Fetch your data like:</span>
<span class="hljs-keyword">const</span> user = <span class="hljs-built_in">JSON</span>.parse(<span class="hljs-built_in">localStorage</span>.getItem(<span class="hljs-string">'details'</span>));
</code></pre>
<h3 id="heading-cookies">Cookies</h3>
<p>Cookie is also type of web storage that is associated with the server i.e either sent by the server in header or set in Javascript. With every HTTP request they are sent server.</p>
<ul>
<li><p>Storage limit is very small i.e around 4KB.</p>
</li>
<li><p>Can be triggered by Site functionality as well as server headers.</p>
</li>
<li><p>The Cookie header is optional and may be omitted if, for example, the browser's privacy settings block cookies.</p>
</li>
</ul>
<blockquote>
<p>Users shouldn’t always rely on cookies as these can be cleared, disabled or blocked from client side so should be considered using for session details or tracking analytics.</p>
</blockquote>
<p>Example</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Set tracking and analytics</span>
<span class="hljs-built_in">document</span>.cookie = <span class="hljs-string">"trackingId=123456789#"</span>;
</code></pre>
<h3 id="heading-indexeddb"><strong>IndexedDB</strong></h3>
<p>IndexedDB allows you to store data permanently in a user's browser. It enables web applications with advanced query capabilities to function seamlessly, whether online or offline, without relying on network access.</p>
<ul>
<li><p>IndexedDB is suitable for storing large amounts of structured data.</p>
</li>
<li><p>Saving large files or search indexes to boost speed and efficiency.</p>
</li>
<li><p>CRUD actions can be executed on the database.</p>
</li>
</ul>
<blockquote>
<p>Storing user-generated content and large files in structured data to improve performance.</p>
</blockquote>
<pre><code class="lang-javascript"><span class="hljs-comment">// Open database</span>
<span class="hljs-keyword">const</span> db = <span class="hljs-keyword">await</span> openDB(<span class="hljs-string">'files'</span>, <span class="hljs-number">1</span>, {
    upgrade(db) {
        db.createObjectStore(<span class="hljs-string">'cache'</span>);
    }
});

<span class="hljs-comment">// Add file to browser cache </span>
<span class="hljs-keyword">const</span> blob = <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">'uploaded.jpg'</span>).then(<span class="hljs-function"><span class="hljs-params">r</span> =&gt;</span> r.blob());

<span class="hljs-keyword">const</span> transact = db.transaction(<span class="hljs-string">'cache'</span>, <span class="hljs-string">'readwrite'</span>);
transact.objectStore(<span class="hljs-string">'cache'</span>).add(blob, <span class="hljs-string">'uploaded.jpg'</span>);

<span class="hljs-comment">// Get cached file</span>
<span class="hljs-keyword">const</span> transact2 = db.transaction(<span class="hljs-string">'cache'</span>);

<span class="hljs-keyword">const</span> file = <span class="hljs-keyword">await</span> transact2.objectStore(<span class="hljs-string">'cache'</span>).get(<span class="hljs-string">'uploaded.jpg'</span>);
</code></pre>
<p>For secure web storage, adhere to these guidelines:</p>
<ul>
<li><p>Limit storage to non-sensitive data</p>
</li>
<li><p>Always use HTTPS</p>
</li>
<li><p>Enforce access controls</p>
</li>
<li><p>Encrypt any sensitive information</p>
</li>
<li><p>Sanitize input data</p>
</li>
<li><p>Protect against XSS attacks.</p>
<p>  By following these practices, developers can safely utilize web storage and reduce potential security risks.</p>
</li>
</ul>
<p><strong>Reference -</strong> <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage"><strong>mdn web docs_</strong></a></p>
]]></content:encoded></item><item><title><![CDATA[Capacitor integration with Nuxt app for Android, iOS and Electron]]></title><description><![CDATA[Capacitor is an open source native runtime for building cross-platform mobile and Progressive Web Apps, with JavaScript, HTML, and CSS.For this first we will need a nuxt.js application where we will integrate our capacitor. Nuxt.js can be seen from t...]]></description><link>https://blog.anshvarun.com/capacitor-integration-with-nuxt-app-for-android-ios-and-electron</link><guid isPermaLink="true">https://blog.anshvarun.com/capacitor-integration-with-nuxt-app-for-android-ios-and-electron</guid><category><![CDATA[Nuxt]]></category><category><![CDATA[capacitor]]></category><category><![CDATA[Electron]]></category><category><![CDATA[Android]]></category><category><![CDATA[iOS]]></category><category><![CDATA[integration]]></category><dc:creator><![CDATA[ANSH VARUN]]></dc:creator><pubDate>Sun, 30 Jun 2024 15:35:28 GMT</pubDate><content:encoded><![CDATA[<p><img src="https://robomx.com/cms/untitled-design-3-.png" alt="Capacitor Integration with Nuxt App for Electron, Android and iOS" /></p>
<p><strong>Capacitor</strong> is an open source native runtime for building cross-platform mobile and Progressive Web Apps, with JavaScript, HTML, and CSS.<br />For this first we will need a <strong>nuxt.js</strong> application where we will integrate our capacitor. Nuxt.js can be seen from the <a target="_blank" href="https://nuxtjs.org/docs/2.x/get-started/installation">docs here</a>.</p>
<p><a target="_blank" href="https://capacitorjs.com/docs/getting-started">Capacitor</a> allows to build our app with modern web components that is cross-platform that is Android, iOS, PWA and electron.</p>
<p>Lets start with adding Capacitor to an existing Nuxt app.</p>
<h4 id="heading-add-capacitor">Add CAPACITOR</h4>
<p>To add Capacitor to your web app, run the following commands:</p>
<pre><code class="lang-plaintext">cd my-nuxt-app
npm install @capacitor/core @capacitor/cli
</code></pre>
<p>Lets initialize Capacitor with our app’s information. This command below will generate '<strong>capacitor.config.js’</strong> file where we can add app information.</p>
<pre><code class="lang-plaintext"> npx cap init
</code></pre>
<p>Lets see how our capacitor.config.js files look</p>
<pre><code class="lang-plaintext">{
  "appId": "com.example.app",
  "appName": "MyNuxtApp",
  "bundledWebRuntime": false,
  "npmClient": "npm",
  "webDir": "www",
  "plugins": {
    "SplashScreen": {
      "launchShowDuration": 0
    }
  },
  "cordova": {}
}
</code></pre>
<h2 id="heading-link-nuxt-to-capacitor">LINK NUXT TO CAPACITOR</h2>
<p>Use the <strong>–web-dir</strong> flag to set the web assets folder (the default is <em>www</em>)<br />Configuring this <strong>capacitor.config.json</strong> will link our nuxt app to capacitor. We need to change</p>
<p><code>"webDir": "www" to "webDir": "dist"</code></p>
<p>Also, we can configure our <strong>“appId”</strong> and <strong>“appName”</strong>. Now our app is ready to be compiled and build.</p>
<p><code>yarn run generate</code></p>
<p><code>yarn dev</code></p>
<p>We have successfully added Capacitor to our Nuxt.js app.</p>
<h1 id="heading-lets-add-platforms">Lets add Platforms :</h1>
<h3 id="heading-electronhttpscapacitor-communitygithubioelectrongetting-startedindex"><a target="_blank" href="https://capacitor-community.github.io/electron/#/./getting-started/index"><strong>Electron</strong></a></h3>
<p>Run the command below in your root directory to install the platform for use with the <strong>@capacitor/cli</strong></p>
<p><code>npm i @capacitor-community/electron</code></p>
<p>Lets initiate platform to create electron folder in our nuxt app.</p>
<p><code>npx cap add @capacitor-community/electron</code></p>
<p>So we have successfully added the electron platfrom to our application. Lets open it</p>
<p><code>npx cap open @capacitor-community/electron</code></p>
<p><a target="_blank" href="https://capacitorjs.com/docs/basics/running-your-app"><strong>Android &amp; iOS</strong></a></p>
<p><code>npx cap add android</code></p>
<p><code>npx cap add ios</code></p>
<p>Lets copy all of our web code from <strong>/dist</strong> to our native app directories for mobile platform functionalities. <em>Specific modifications</em> in IDE can made for each.</p>
<p><code>npx cap copy</code></p>
<p>Our code will be updated too with this.<br />For opening Android application :</p>
<p><code>npx cap open android</code></p>
<p>Make sure to have Android Studio with <em>gradle</em> build setup to generate apk.</p>
<p>For opening iOS application :</p>
<p><code>npx cap open ios</code></p>
<p><strong>XCode</strong> will be opened and we can run our app.</p>
<p><a target="_blank" href="https://capacitorjs.com/docs/basics/running-your-app#progressive-web-app"><strong>Progressive Web App</strong></a></p>
<p>Capacitor has a tiny development web server for local testing, but it’s recommended to run your web app using your framework of choice’s server tools.</p>
<p><code>npx cap serve</code></p>
<p>Generating resources</p>
<ol>
<li><p>Create <em>resources</em> folder in root directory.</p>
</li>
<li><p>Add <em>icon.png</em> with size - 1024x1024 px Add <em>splash.png</em> with size - 2732x2732 px</p>
</li>
<li><p>So we have placed icon and splash in resources folder, now we need these in all sizes compatible with our android and ios platforms.</p>
</li>
<li><p>Lets add script to generate it and then <em>sync</em> it to platform.</p>
</li>
<li><p>Add the following command to scripts in <strong>package.json</strong> file of nuxt app</p>
</li>
</ol>
<p><code>"resources": "cordova-res-generator -p android,ios &amp;&amp; node resources/sync.js android"</code></p>
<p>As we see, we have used <a target="_blank" href="https://www.npmjs.com/package/cordova-res-generator#installation"><strong>cordova-res-generator</strong></a> so lets install this generator by command</p>
<p><code>yarn add --dev cordova-res-generator</code></p>
<p>We have successfully add res-generator now we are ready to go but we still have <strong>node resources/sync.js android</strong></p>
<p>This will sync the resources to android platform using sync.js, so lets add sync.js in resources where we have added our icon and splash</p>
<p><a target="_blank" href="https://github.com/anshcena/blog/blob/main/nuxt-capacitor/sync.js">Sync.js</a></p>
<p>Copy the code from above mentioned <a target="_blank" href="https://github.com/anshcena/blog/blob/main/nuxt-capacitor/sync.js">Sync.js</a> to generate sync.js inside resources.</p>
<p>so our resources will have these 3 :</p>
<p><img src="https://github.com/anshcena/blog/blob/main/nuxt-capacitor/img/sync%20file.jpg?raw=true" alt="Structure resources" /></p>
<p>We are ready to generate and sync now</p>
<p><code>yarn resources</code></p>
<p>🎉 Resources are generated and sync to platfrom - <strong>android</strong> 🎉</p>
<p>For <strong>iOS</strong> , we can make change in scripts of package.json as <strong>node/sync.js ios</strong></p>
<p><em>Make sure to put logo in splash screen in middle as well as small for better resource generated results and optimized images.</em></p>
<h3 id="heading-resources-for-electron">Resources for Electron</h3>
<p><img src="https://github.com/anshcena/blog/blob/main/nuxt-capacitor/img/electron%20resources.jpg?raw=true" alt="Rersource" /></p>
<p>Replace these assets icons from your icons</p>
<h1 id="heading-packaging-our-electron-app-to-executable-file">Packaging our <strong>Electron</strong> app to executable file</h1>
<p>We will be using <a target="_blank" href="https://www.npmjs.com/package/electron-builder">electron-builder</a> so install using :</p>
<p><code>npm i electron-builder</code></p>
<p>Add script in <strong>package.json</strong> inside electron root folder.</p>
<pre><code class="lang-plaintext">"electron:pack": "npm run build &amp;&amp; electron-builder build --dir",
"electron:build-windows": "npm run build &amp;&amp; electron-builder build --windows",
"electron:build-mac": "npm run build &amp;&amp; electron-builder build --mac"
</code></pre>
<p>We have added build script as well as for <strong>mac</strong> and <strong>windows</strong> application.</p>
<p>Run Command :</p>
<p><code>yarn electron:build-windows // windows</code></p>
<p><code>yarn electron:build-mac // mac</code></p>
<p>🔥 We have generated our execcutable files with this script 🔥</p>
<p><em>App name and package can be changed from build inside<strong><strong>package.json</strong></strong>of electron</em></p>
<p><a target="_blank" href="https://github.com/MexsonFernandes/nuxt-capacitor-app#create-resources">Reference - Resource Generator- MexsonFernandes/nuxt-capacitor</a></p>
]]></content:encoded></item></channel></rss>